All the variables that are to be used in a program must be declared first. The declaration of variable means specifying the identifier (i.e. variable name), the type and width of data it will hold (i.e. data type) to the compiler. The general syntax of declaring a variable in C is as follows:
Also, multiple variable declaration of same data type in a single line is possible. The general syntax for this is as follows:
Data-type Variable-name1[, … Variable-nameN];
This means the above 4 statements can written in 2 statements as follows:
int x, abc;
float y, def;
Please note that as every sentence in English language ends with a period (.), every statement in C language ends with a semi-colon (;) called terminator. Table – 1 shows some valid and invalid examples of variable declaration in C language.
Table – 1: Some valid and invalid examples of variable declaration in C