Variable declaration and Data Types:
In C language, variables are used as the repository to store some value. The value may be unchangeable throughout the execution of the program or may be a temporary variable that can change its value in the course of program execution (based on user input or dependencies on other variables).
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6;
clrscr();
printf("The value of a is %d and b is %d",a,b);
getch();
}
Tha above program simply stores two integer values in two variables 'a' and 'b' and displays the stored value when executed.
The first line of the main function depicts the variable declaration. Two variables named 'a' and 'b' with integer data type is declared. The data type is the one that says which type of data the variable holds.
int - integer
fload - decimal
char - characters
long int - long integers
double - numbers with 8 values after decimal point.
These are the normally used data types. Other than this many rarely used data types are there, that we will discuss on upcoming chapters.
Normally an integer will occupy 2 bytes but in modern compilers it is 4 bytes of memory. char datatype occupies 1 memory byte and float will occupy 4 bytes and double 8 bytes of memory.
%d - integer data
%c - character type data
%f - float type of data
The printf function in the above program uses these specifiers to print the value of variable. However the variable name should be written in same order separated by comma.
SYNTAX:
printf("%d %d", variable1, variable2);
if you want to print the second variable first, then
printf("%d %d",variable2,variable1);
These specifiers used inside double quotes always takes the value of corresponding variables.
Thank you.... :)