









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to variables and declarations in c programming. It explains what variables are, their declaration process, and the importance of declaring variables. The document also covers the rules for declaring variables, simple declaration examples, initialization, data types, and placement of declarations.
Typology: Lecture notes
1 / 16
This page cannot be seen from the preview
Don't miss anything!










how we introduce an identifier
specifies the interpretation and attributes of an identifier
in other words, tells the computer what an identifier means
variable
function
various other things
let’s focus on variables right now
its data type
anything else that the compiler needs to know
storage class
right now, we’ll just stick to the first two
int, double, char…
remember the rules for identifiers
case sensitive
of a data type the compiler can convert into the data type of the variable
double b = 12;double a = 19.38;int i = 3;
float f = 12.34;char c = 3.1415;
At beginning of statement block
this is what we’ve seen so far
Outside a function - global variable
Parameter declaration - in function declaration
/ / conversion table FtoC1 – print a Fahrenheit-to-Celsius { int main (void)#include <stdio.h> while (fahr <= upper) {fahr = lower;int step = 20;int upper = 300;int lower = 0;int celsius;int fahr; fahr = fahr + step;printf (“%d\t%d\n”, fahr, celsius);celsius = 5 * (fahr – 32) / 9; return 0;} }**
but those variables are only available to the code inside the statement block
this is a concept called scope…
remember my driving analogy of a function
the same instructions, no matter what X is each time
remember how we have used printf: printf (“Hello, world!\n”); printf (“i is %d\n”, i); printf (“%d\t%d\n”, fahr, celsius);
we’ll talk about parameters more when we get into functions