Assume that an integer occupies 4 bytes. What will be the output of the following C program?

#include <stdio.h>

int main()
{
int x = 10;
printf("%d", sizeof(x));
return 0;
}
                        

Options

  • A. 2
  • B. 4
  • C. 10
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. 4

Detailed Explanation

Correct Answer: 4

The sizeof operator returns the amount of memory occupied by its operand.

Here, x is declared as an integer:

int x = 10;

The question explicitly states that an integer occupies 4 bytes. Therefore, sizeof(x) returns 4.

Notice that sizeof does not return the value stored in x. The value of x is 10, but its size is 4 bytes.