write a program for size of a data type without using
sizeof() operator?

Answer Posted / sunil

This has been solved in parts. I am not sure if there are
any better method merging it.

case 1. User passes a variable as the parameter.
eg: int n;
sizeof(n);

case 2. User passes a data type as the parameter.
eg: sizeof(int)


Solution
case 1: #define GetSize(x) (char*)(&x + 1) - (char*)&x

case 2:#define GetMySize(x) (char*)((x*)10 + 1) - (char*)10

Is This Answer Correct ?    15 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

the question is that what you have been doing all these periods (one year gap)

1885


What is new line escape sequence?

1053


What is nested structure in c?

839


What was noalias and what ever happened to it?

811


What do header files do?

846


main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }

890


What are the benefits of c language?

911


what value is returned to operating system after program execution?

1860


When can you use a pointer with a function?

783


What's the best way of making my program efficient?

867


Is null valid for pointers to functions?

889


How to throw some light on the b tree?

858


What is the use of clrscr?

836


What is the difference between union and structure in c?

820


What is scope of variable in c?

809