-> C++ is a strongly-typed language, and requires every variable to be declared with its type before its first use.
-> This informs the compiler the size to reserve in memory for the variable and how to interpret its value.
-> The syntax to declare a new variable in C++ is straightforward: we simply write the type followed by the variable name (i.e., its identifier).
Declaring More than one Variable
If declaring more than one variable of the same type, they can all be declared in a single statement by separating their identifiers with commas.
-> This informs the compiler the size to reserve in memory for the variable and how to interpret its value.
-> The syntax to declare a new variable in C++ is straightforward: we simply write the type followed by the variable name (i.e., its identifier).
Syntax:
char c; //character variable declaration.
int area; //integer variable declaration.
float num; //float variable declaration
Once declared, the variables c, area and num can be used within the rest of their scope in the program.
char c; //character variable declaration.
int area; //integer variable declaration.
float num; //float variable declaration
Once declared, the variables c, area and num can be used within the rest of their scope in the program.
Declaring More than one Variable
If declaring more than one variable of the same type, they can all be declared in a single statement by separating their identifiers with commas.
int a, b, c; //more than one variable declaration.
This declares three variables (a, b and c), all of them of type int, and has exactly the same meaning as:
int a; //integer variable declaration.
int b; //integer variable declaration.
int c; //integer variable declaration.
int b; //integer variable declaration.
int c; //integer variable declaration.