[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

C Programming :: Floating Point Problems - Discussion

Home > C Programming > Floating Point Problems > MCQs Questions Discussion

6 / 6

Choose the correct option.

#include

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

A8

B4

C1

Dcompiler error

Answer: Option (Login/Signup)

Show Explanation

#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 Societe Generale

Post Your Answer Here:     

Reply    
Rate This: +1 -0 +
    Report


Report Error

Please Login First Click Here