How to find the size of data without using the sizeof() operator?

Questions by kaliswaranbsc   answers by kaliswaranbsc

Showing Answers 1 - 3 of 3 Answers

baseersd

  • Sep 18th, 2007
 

Here is the code for finding the size of data types without using sizeof()



#include<stdio.h>
#define size_of(data) ( (char *)(&data +1) - (char *)(&data))
int main()
{
    int INT;
    char CHAR;
    float FLOAT;
    double DOUBLE;
    printf("Sizeof int ::%dn",size_of(INT));
    printf("Sizeof char ::%dn",size_of(CHAR));
    printf("Sizeof float ::%dn",size_of(FLOAT));
    printf("Sizeof double ::%dn",size_of(DOUBLE));
    
    system("pause");
    return 0;
        
}


Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions