ProgrammingHardProduct company OA
With 4-byte int, what is printed?
With 4-byte int, what is printed?
int *p = (int[]){10, 20, 30};
p[1] += 5;
printf("%d %zu", p[1] + p[2], sizeof((int[]){10, 20, 30}) / sizeof(int));- A. 55 1
- B. 55 2
- C. 55 3
- D. 50 3
Correct answer: C. 55 3
A compound literal (C99) creates an unnamed, modifiable array; p points to its first element, so p[1] becomes 25 and 25 + 30 = 55. sizeof applied to the compound literal itself sees an array of 3 ints (12 bytes), not a pointer, giving 3.
More C Programming questions
- What is printed? c #define COUNT(...) (sizeof((int[]){VAARGS}) / sizeof(int)) printf("%zu %zu", COUNT(1, 2, 3), COUNT(7));
- After the call below, what is c? c int c = 0; void perm(char s, int k, int n) { if (k == n) { c++; return; } for (int i = k; i < n; i++) {…
- What is printed? c int steps = 0; int gcd(int a, int b) { steps++; return b == 0 ? a : gcd(b, a % b); } int main(void) { int g = gcd(1071…
- What is printed? c unsigned v = 0; const char b = "10110"; while (b) v = (v << 1) | (b++ - '0'); printf("%u", v);
- With 4-byte int, what is printed? c int a[2][3][4]; printf("%zu %zu %td", sizeof a[1], sizeof a[1][2], (char )&a[1][2][3] - (char )a);
- Assume ASCII. What is printed? c int my(const char a, const char b) { while (a && a == b) { a++; b++; } return a - b; } int main(void) {…