ProgrammingHardProduct-company MCQ pattern
With 4-byte int, what is printed?
With 4-byte int, what is printed?
int i = 5;
size_t s = sizeof(i++);
printf("%d %zu", i, s);- A. 6 4
- B. 6 8
- C. 5 4
- D. 5 5
Correct answer: C. 5 4
sizeof does not evaluate its operand (unless it is a variable-length array); it only needs the type. So i++ never executes: i stays 5, and sizeof(int) is 4.
More C Programming questions
- What is printed? c int a = -1; unsigned int b = 1; if (a < b) printf("less"); else printf("not less");
- What is printed? c float f = 0.1f, g = 0.5f; printf("%s ", f == 0.1 ? "eq" : "ne"); printf("%s", g == 0.5 ? "eq" : "ne");
- On a little-endian machine with 4-byte int and ASCII, what is printed? c union { int i; char c; } u; u.i = 0x41424344; printf("%c", u.c);
- What is printed? c void swap(int x, int y) { x ^= y; y ^= x; x ^= y; } ... int a = 7; swap(&a, &a); printf("%d", a);
- On a two's-complement machine, what is printed? c printf("%d %d", 40 & -40, 40 & (40 - 1));
- For a signed int n on a two's-complement machine, how many of these are correct? (i) (n & (n - 1)) == 0 is true for every positive power…