Here a, f are variables and int, float are data types.
We can also provide values while declaring the variables as given below :
int a=10, b=20; // this is called declaration, not an assignment.
float f;
f=15.5; //this is not an initialization, it is called assignment.
1. Local Variables
2. Global Variables
Local variables scope is confined within the block or function where it is defined. Local variables must always be defined at the top of a block.
When a local variable is defined, it is not initialized by the system, you must initialize it yourself.
When execution of the block starts the variable is available, and when the block ends the variable 'dies'. It must be declared at the start of the block.
void function1()
{
int x=10; //local variable
}
Global variable is defined at the top of the program file and it can be visible and modified by any function that may reference it.
Global variables are initialized automatically by the system when you define them.
If same variable name is being used for global and local variable then local variable takes preference in its scope. But it is not a good practice to use global variables and local variables with the same name.
int value=20; //global variable
void function1()
{
int x=10; //local variable
}