Variables:Variables are the storage location in memory that holds some value. We define a variable to make sure a stored value in memory is accessible by user later. Variables are accessed by their identifiers(Symbolic name that refer to the value stored in the memory) to which they are linked with. In order to use any variable and the value it contains, the variable must be declared first.
Declaring variables in C:Syntax: data-type variable-name;
Here data-type refers to valid C Data type.
And variable-name refers to valid C identifier.
Note: In C all variables must be declared on the top.
Initializing a variable:Assigning a value to the variable is called as initializing a variable. Values are initialized or assigned to any variable using assignment operator =.
Declaring multiple variables:Multiples variables in C can be declared one after another declaration.
int num2 = -30;
unsigned int num3 = 10;
float num4 = 1.2;
char ch = 'a';
Note: Values of character variable must be assigned inside a single quote. And must only contain single character.
Declaring multiple variables of same type:Multiple variables of same type can be declared and initialized by separating them with comma,.
int num4 = 10, num5, num6 = -1290;
View next C tutorial How to take simple input from user.