This is C program that asks user to define the size of data types acquired by them. Data types are known as those elements that tells the user which kind of data elements they have for example integer type for numeric value, char type for characters. All the data types have their limits for numerical expressions like char is 0-255 bits.
In this program user to define the size of data types. User declares a variable int i for storing or contain the value that will be imprinted as result on the screen. All the data types are printed through the print method. User also declares a method to fetch out the size of data types.
Problem Statement:
This is C program example to fetch out the size of data types.
- Declare variable.
- Define method to fetch out data type size.
- Display result on the screen.
Here is C source code for fetching out the data types size. Output of this program shown below.
#include <stdio.h>
void main()
{
int i;
clrscr();
printf(" short int is %2d bytes \n", sizeof(short int));
printf(" int is %2d bytes \n", sizeof(int));
printf(" int * is %2d bytes \n", sizeof(int *));
printf(" long int is %2d bytes \n", sizeof(long int));
printf(" long int * is %2d bytes \n", sizeof(long int *));
printf(" signed int is %2d bytes \n", sizeof(signed int));
printf(" unsigned int is %2d bytes \n", sizeof(unsigned int));
printf("\n");
printf(" float is %2d bytes \n", sizeof(float));
printf(" float * is %2d bytes \n", sizeof(float *));
printf(" double is %2d bytes \n", sizeof(double));
printf(" double * is %2d bytes \n", sizeof(double *));
printf(" long double is %2d bytes \n", sizeof(long double));
printf("\n");
printf(" signed char is %2d bytes \n", sizeof(signed char));
printf(" char is %2d bytes \n", sizeof(char));
printf(" char * is %2d bytes \n", sizeof(char *));
printf("unsigned char is %2d bytes \n", sizeof(unsigned char));
getch();
}