| |
|
C Variables
Variable are use to store data and its value can be changed as well as it can be reused many times as we wants. Or we also can say that variable is a name of memory location.
We can also say that it is the way to represent memory location through symbol so that it can be easily identified.
Below is the syntax to define the variable:-
type variable_name;
And below is the example to declare variable:-
int x;
float y;
char z;
Here in above x,y,z are variables. And int, float, char are different data types.
We can also set the value to the variable as per given below syntax:-
int x=10,n=20; //declare 2 varible in single line with values
float y=10.98;
char z='A';
Rules to define variables
Below are 4 most important rules when defining variables in C language:-
(1)We can use alphabets, digits and underscore.
(2)We can start variable with alphabet and underscore only. But it cannot start with a digit.
(3)We cannot use whitespace in variable name.
(4)we cannot use variable name that is reserved word or keyword like int,float, char etc.
valid variable names:-
int a;
int _xyz;
int x20;
Invalid variable names:-
int 2;
int a b;
int long; | |
|
|
|
|