-
Notifications
You must be signed in to change notification settings - Fork 0
/
26_macro_sizeof.c
50 lines (45 loc) · 1.62 KB
/
26_macro_sizeof.c
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
/*****************************************************************************************************
DOCUMENTATION:
Name : V.Karthikeyan
Date : 01.08.2021
Description : To define a macro SIZEOF(x), where x is a variable, without using sizeof operator
Input : ./a.out./a.out
size of Int :4
size of Short int :2
size of Char :1
size of Float :4
size of Double :8
size of Long Double :16
size of Lont_long_int :8
size of Signed_char :1
size of Unsigned_short_int :2
size of Unsigned_int :4
******************************************************************************************************/
#include<stdio.h>
//to calculate the size of data_type
#define SIZE_OF(x) (char *)(&x+1) - (char *)&x
int main()
{
int Integer;
short int Short_int;
char Char;
float Float;
double Double;
long double Long_double;
long long int Long_long_int;
signed char Signed_char;
unsigned short int Unsigned_short_int;
unsigned int Unsigned_int;
long int Long_int;
printf("\nsize of Int\t\t\t:%lu ",SIZE_OF(Integer));
printf("\nsize of Short int\t\t:%lu ",SIZE_OF(Short_int));
printf("\nsize of Char\t\t\t:%lu ",SIZE_OF(Char));
printf("\nsize of Float\t\t\t:%lu ",SIZE_OF(Float));
printf("\nsize of Double\t\t\t:%lu ",SIZE_OF(Double));
printf("\nsize of Long Double\t\t:%lu ",SIZE_OF(Long_double));
printf("\nsize of Lont_long_int\t\t:%lu ",SIZE_OF(Long_long_int));
printf("\nsize of Signed_char\t\t:%lu ",SIZE_OF(Signed_char));
printf("\nsize of Unsigned_short_int\t:%lu ",SIZE_OF(Unsigned_short_int));
printf("\nsize of Unsigned_int\t\t:%lu\n",SIZE_OF(Unsigned_int));
return 0;
}