Wednesday, 8 October 2014

Declaration of variables in c programming

If you want to declare variable of type integer then declare it as
int a;
Here your variable is 'a' if type integer. You can store values of type integer to the variable 'a'.
Similarly character variable is declared as
char b;
you can assign values to integer variable as
example-
a=9;
For assigning character  to character variables the character should be written in single quote mark.
example-
b='a';
Without making separate statements you can do declaration and assignment int single statement.
int a=5;
char b='m';
you can also do declaration of multiple variables of same type.
example-
int a,b;
int c=9,d,e=3;
char z='a',y='x';
there are also some different data types like float, double etc.
float type variable can store real numbers
example-
float a=2.2;
float type variables can store integer variables only in real form
example-
float a=2.0;
double type variable can store both integer or frosting type numbers.
example-
double a=2,b=2.2;
There are some other dat noa types like long int etc. Basically int variable can store values from -32768 to 32767. But if you want to store a value out of this range then the variable of data type long int will provide this facility.
example-
long int a=33333;
long int has very big range.
The number of bytes required to store a value of a particular data type in the particular variable of that data type are as follows-
Data type           bytes
char                         1
int                            2
float                         4
long int                   8
double                    8

No comments:

Post a Comment