implement your own sizeof() operator

#include <stdio.h>
#define mySizeof(type) ((char *)(&type+1)-(char *)(&type))
int main()
{
        char x;
        int y;
        double z;
        printf("mySizeof(char) is : %d\n", mySizeof(x));
        printf("mySizeof(int) is : %d\n", mySizeof(y));
        printf("mySizeof(double) is : %d\n", mySizeof(z));
        return 0;
}



Output :
mySizeof(char) is : 1
mySizeof(int) is : 4
mySizeof(double) is : 8

No comments:

Post a Comment