ProgrammingVery hardGATE CS · Campus placements
Which statement about sizeof is correct when x is an int variable initialised to 5?
- A. sizeof(x++) increments x to 6
- B. sizeof evaluates its operand at run time every time
- C. sizeof(x++) leaves x unchanged, because the operand is not evaluated, except for variable-length array types
- D. sizeof is a library function called at run time
Correct answer: C. sizeof(x++) leaves x unchanged, because the operand is not evaluated, except for variable-length array types
sizeof is resolved from the operand's type, so the operand is not evaluated except when it has a variable-length array type. Hence x++ inside sizeof has no effect on x.
More C Programming questions
- char s[] = "hello"; printf("%zu %zu", sizeof s, strlen(s)); prints what?
- char names[] = {"ab", "cde", "f"}; What is strlen(names[0]) strlen(names[1]) + strlen(names[2])?
- int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int (ops[])(int, int) = {add, sub, add}; int r = 10; for…
- uint32t a = 4000000000u; uint32t s = a + a; What is s?
- uint32t lo = 3000000000u, hi = 3500000000u; uint32t mid = (lo + hi) / 2; What is mid?
- uint32t x = 0u; Which statement about the test (x & (x - 1)) == 0 is correct?