Variable in c language
Definition of variable-
C variable is named location in a memory where a program can manipulate the data. This location is used to hold the value of the variable.
The value of a c variable may get changed in the program. C variable might be belonging to any of the data type like int ,char, float or string etc.
Declaration of variable-
Declaration of variable can be done in C by using following syntax:
data_type variable_name;
Or
data_type variable1,va variab2,...,variable n;
Where data_type is any valid c data type and variable_name is any valid identifier.
For eg. int a,b,c;
float a,b;
Variable declaration tells the compiler only two things-
1. Name of the variable.
2 . The type of data that variable will hold.
Initialization of variables-
In C programming language variable can be initialized in the declaration statement of any block (either it may main's block or any other function block).
While declaring a variable we can provide a value to the variable with assignment operator.
Syntax of the initialization of the variable:
data_type variable_name=value;
For eg. int a=10;
float=5.80
char='m';
int at[5]={1,2,3,4,5};
Scopes of variables-
Scope refers to the visibility of variables or we can say that scope is a region of a program. Variable scope is a region in a program where a variable is declared and used. So we can have three types of scopes depending on the region where these are declared and used-
1. Local variable-local variable are defined inside a function or a block.
2. Global variable-Global variable are defined outside all the functions.
3. Formal parameters- formal parameters are defined in function parameter.
Definition of variable-
C variable is named location in a memory where a program can manipulate the data. This location is used to hold the value of the variable.
The value of a c variable may get changed in the program. C variable might be belonging to any of the data type like int ,char, float or string etc.
Declaration of variable-
Declaration of variable can be done in C by using following syntax:
data_type variable_name;
Or
data_type variable1,va variab2,...,variable n;
Where data_type is any valid c data type and variable_name is any valid identifier.
For eg. int a,b,c;
float a,b;
Variable declaration tells the compiler only two things-
1. Name of the variable.
2 . The type of data that variable will hold.
Initialization of variables-
In C programming language variable can be initialized in the declaration statement of any block (either it may main's block or any other function block).
While declaring a variable we can provide a value to the variable with assignment operator.
Syntax of the initialization of the variable:
data_type variable_name=value;
For eg. int a=10;
float=5.80
char='m';
int at[5]={1,2,3,4,5};
Scopes of variables-
Scope refers to the visibility of variables or we can say that scope is a region of a program. Variable scope is a region in a program where a variable is declared and used. So we can have three types of scopes depending on the region where these are declared and used-
1. Local variable-local variable are defined inside a function or a block.
2. Global variable-Global variable are defined outside all the functions.
3. Formal parameters- formal parameters are defined in function parameter.
No comments:
Post a Comment