Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.


Please wait...

C Programming :: Floating Point Problems

6. #define mysizeof(a) (&a+1) - &a
void main()
{
float d;
printf("%d\n", mysizeof(d) );
}
note: assume sizeof float is 8 bytes

Answer: Option C

Explanation :

Tricky ... little bit .. basically in below line &a (address of float variable d) getting subtracted from address of variable + 1 i.e incrementing it with 1 gives the address where the next variable of the type d can be stored, the answer is 1 instead of 8 (as given float size is 8 byte).

#define mysizeof(a) (&a+1) - &a

The difference gives the result that how many variables of type of d can be stored in that amount of memory which will obviously be 1 for the type d. The result of pointer subtraction is in elements and not in bytes. so, that the below expression evaluates to 1. instead of 8.

If you above statement put like below, the answer will be 8.

#define mysizeof(a) (char*)(&a+1) - (char*)&a

typecasting it int char* and taking the difference will tell us how many variables of type char can be stored in the given memory space (the difference). Since each char requires only 1 Byte of memory therefore (amount of memory)/1 will give the number of bytes between two successive memory locations of the type of variable passed on to the macro and hence, the amount of memory that the variable of type d requires i.e 8 bytes.

Asked In :: Global Edge

Post Your Answer Here:     

q4i-reply-your-answer Reply     |    Rate This: +1 -0      |     Report     |     To Reading List



Report Error

Please Login First Click Here