- C variables is a named location in a memory where a c program can manipulate the data. Memory location is used to hold the value of the variable.
- The value of the C variables may get change in the c program.
- Variables are what make your c programs zoom.
- C variables might be belonging to any of the data type like int, float, char,double,array etc.
Naming Rules for C Variables
- First Character should be Underscore or Alphabet
- Blanks & Commas are not allowed for declaration
- Characters Allowed for declaration :
- Digits ( 0 – 9 )
- Small Letters ( a – z )
- Capital Letters ( A – Z )
- Variable name Should not be Reserved Word (Ex. if, else, switch, case etc.)
- No Special Symbols other than underscore(_) are allowed for declaration
data_type variable1, variable2,…,variablen;
where, data_type is any valid c data type and variable_name is any valid identifier.
Constant and Volatile Variables
C variables having same or unchanged value during the execution of a c program are called constant variables. A variable declared using keyword const.
const int a=50;
Those variables that can be changed at any time by some external sources from outside or same program are called volatile variables.
Any variable declared as volatile using keyword volatile.
volatile data_type variable_name;
Variable initialization means assigning a value to the variable with ‘=’ operator.
int x = 10, y = 30;
char flag = ‘x’, ch=’l’;
Types of Variables
- Local variable
- Global variable
- Environment variable
- The scope of local variables will be within the function body only.
- These variables are declared within the function and can’t be accessed outside of the function.
- The scope of global variables will be throughout the program.
- These variables can be accessed from anywhere in the program.
- This variable is defined outside the main function. So that, this variable is visible to main function and all other sub functions.
- Environment variable is a variable that will be available for all C applications and C programs.
- We can access these variables from anywhere in a C program without declaring and initializing in C program.
- The Inbuilt functions which are used to access, modify and set these environment variables are called Environment functions.
For More C Data Types