Syntax :
datatype variable_name;
Example :
int a;
float f;
// bool is the new datatype, it can stores true or false value.
bool a;
char c;
There is a important difference between C and C++ regarding when local variable can be declared. In c, you must declare all local variables used within a block at the start of that block. You cannot declare a variable in a block after an “action” statement has occurred.
Example :
// Incorrect in C. Ok in C++
int function()
{
int num1;
num1 = 10;
/*
won't compile as a C program
but compiling as C++ program its OK
*/
int num2;
num2 = num1 * 5;
return num2;
}