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

What are the 4 types of organizational structures?

626


Why are all header files not declared in every c program?

602


about c language

1607


Can include files be nested?

630


Write a code to determine the total number of stops an elevator would take to serve N number of people.

731






What is a nested loop?

652


Is c programming hard?

577


Why is python slower than c?

608


Write the test cases for checking a variable having value in range -10.0 to +10.0?

1819


What does the message "automatic aggregate intialization is an ansi feature" mean?

695


Are pointers really faster than arrays?

567


What is 1d array in c?

602


a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above

876


What does. int *x[](); means ?

639


Write a function which takes as parameters one regular expression(only ? and * are the special characters) and a string and returns whether the string matched the regular expression.

654