Saturday, April 5, 2014

Size of dataTypes

Q. Write a simple program to find the size of different basic data types in c?

Ans.


/*Program of shows of different data types size*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int i;
 char ch;
 float f;

 long l;
 double d; 

 long double ld;
 printf("
Size of different data types as following"
);
 printf("
"
);

 printf("
Size of character ch is %d"
,sizeof(ch));

 printf("
Size of integer is %d"
,sizeof(i)); 
 printf("
Size of float is %d"
,sizeof(f));

 printf("
Size of long is %d"
,sizeof(l));

 printf("
Size of double is %d"
,sizeof(d));

 printf("
Size of long double is %d"
,sizeof(ld));

 getch();
 return 0;
}

 Output of the above programs:

    Size of different data types

 Size of character ch is 1
 Size of integer is 2
 Size of float is 4
 Size of long is 4
 Size of double is 8
 Size of long double is 10

NOTE:-The size of int,long are compiler dependent. The above sizes in this program for 16-bit compiler.


0 comments:

Post a Comment

 

Information Technology News Copyright © 2016 | Powered by Blogger