Variables In C
Variables:
A variable is just a named area of storage that can hold a single value (numeric or character).The C language demands that you declare the name of each variable that you are going to use
along with its type!
How am I supposed to declare a variable?
The tutorial below will help you in understanding this concept. So, open gedit/notepad/notepad++,write the given program, save it as a .c file, compile, and run.
Example:
#includeint main() { int a; /* Declaration */ a = 5; /* Initialization */ /* Printing using printf */ printf(“Wow! CS102 is so much interesting, and I have %d courses in my first semester”, a); return 0; }
Syntax rules for valid variables:
- A variable must consist of only letters, digits and underscore.
- A variable cannot begin with a digit.
- A C reserved word cannot be used as a variable name.
C reserved Words
Declaration and initialization can be done using single statement.
int a = 5; /* Declaration & Initialization using single statement. Try it */