-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram to Find the Size of int, float, double and char
50 lines (40 loc) · 1.33 KB
/
Program to Find the Size of int, float, double and char
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Data Type Memory (bytes) Range Format Specifier
// short int 2 -32,768 to 32,767 %hd
// unsigned short int 2 0 to 65,535 %hu
// unsigned int 4 0 to 4,294,967,295 %u
// int 4 -2,147,483,648 to 2,147,483,647 %d
// long int 4 -2,147,483,648 to 2,147,483,647 %ld
// unsigned long int 4 0 to 4,294,967,295 %lu
// long long int 8 -(2^63) to (2^63)-1 %lld
// unsigned long long int 8 0 to 18,446,744,073,709,551,615 %llu
// signed char 1 -128 to 127 %c
// unsigned char 1 0 to 255 %c
// float 4 %f
// double 8 %lf
// long double 12 %Lf
// To find the size of the four variables:
// The four types of variables are defined in integerType, floatType, doubleType and charType.
// The size of the variables is calculated using the sizeof() operator.
// C program to find the size of int, char,
// float and double data types
#include <stdio.h>
int main()
{
int integerType;
char charType;
float floatType;
double doubleType;
// Calculate and Print
// the size of integer type
printf("Size of int is: %ld",sizeof(integerType));
// Calculate and Print
// the size of charType
printf("Size of char is: %ld",sizeof(charType));
// Calculate and Print
// the size of floatType
printf("Size of float is: %ld",sizeof(floatType));
// Calculate and Print
// the size of doubleType
printf("Size of double is: %ld",sizeof(doubleType));
return 0;
}