Q. Write a simple program to find the size of different basic data types in c?
Ans.
#include<stdio.h>
#include<conio.h>
int main()
{
int i;
char ch;
float f;
long l;
double d;
long double ld;
printf("\n\tSize of different data types as following");
printf("\n");
printf("\nSize of character ch is %d",sizeof(ch));
printf("\nSize of integer is %d",sizeof(i));
printf("\nSize of float is %d",sizeof(f));
printf("\nSize of long is %d",sizeof(l));
printf("\nSize of double is %d",sizeof(d));
printf("\nSize of long double is %d",sizeof(ld));
getch();
return 0;
}
#include<conio.h>
int main()
{
int i;
char ch;
float f;
long l;
double d;
long double ld;
printf("\n\tSize of different data types as following");
printf("\n");
printf("\nSize of character ch is %d",sizeof(ch));
printf("\nSize of integer is %d",sizeof(i));
printf("\nSize of float is %d",sizeof(f));
printf("\nSize of long is %d",sizeof(l));
printf("\nSize of double is %d",sizeof(d));
printf("\nSize 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 integer is 2
Size of float is 4
Size of long is 4
Size of long is 4
Size of double is 8
Size of long double is 10
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.
No comments:
Post a Comment