In this tutorial we will learn how to declare variable in c programming language. A variable deceleration in c programming language involves two ways i.e.,
A variable in c programming language can be declared locally or globally. first we will see an example of local variable declaration.
1. Local Declaration of variable in c program can be easily understood with this program sample.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b; // Variable Declaration In C
return 0;
}
In this case both variable a and b are declared inside the main() functions body therefore there scope is limited to main() function only outside the main() they can not be used.
2. Global Declaration
As the name suggests, In global declaration we declare the variables outside the the main() there in case of global declaration a variable can be used anywhere in the program.
such variables has a wide scope and wide reach in the c program. global declaration can be understood with this example:
#include <stdio.h>
#include <stdlib.h>
int a,b; // Global Declaration In C
int main()
{
return 0;
}
No comments:
Post a Comment