Data type declaration instructions

 Data Type Declaration Instruction

As its name suggests it is used to declare a type of variables in C language. It is a must that you have to declare the type of a variable before using it. And it is also must that these type of declaration instruction should be provided at the beginning of the program (just after the main()).
Data types provided by C language are also known as primitive data types. On various occasions, like during variable creation, you need to specify its ability to hold data of which category. To support such situations, C language provided five reserved words (or keywords). They are known as data types.
  • int
  • char
  • float
  • double
  • void
Now let's learn about some variations in them.
a) We can initialize the variable at the time of its declaration.
Example
int a=3;
char a=’d’;
int a=7*3*2;
b) Remember the order of variables while declaring them.
Example
int i=3,j=5; is same as int j=5,i=3;
However,
float a=5.5,b=a+7.1; is alright, but
float b=a+7.1,a=5.5; is not valid. 
It is because in the above declaration we are trying to use variable an even before defining it.
c) Another interesting point while declaring variables is
Below instruction will work
int a,b,c,d;
a=b=c=10;  
However, the following statement would not work.
int a=b=c=d=10 ;
Now again we are trying to use variables even before defining them.
I hope now you must have to understand the importance of type declaration instruction. So we can only use variables after defining them. And this definition should be written at the starting of the main() body. We cannot define variables anywhere else in the program. If you do so, it will result in an error.

1 comment:

Featured Post

Core and Advance Python

                      Language Fundamentals