ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int a[] = {1, 2, 3}, *p = a;
int x = ++*p++;
int y = *p++ * 10;
printf("%d %d %d %d", x, y, a[0], *p);- A. 2 20 2 3
- B. 3 20 1 3
- C. 2 30 2 3
- D. 2 20 1 3
Correct answer: A. 2 20 2 3
++*p++ parses as ++(*(p++)): the postfix ++ moves p to a[1] but the dereference uses the old address, so a[0] becomes 2 and x = 2. Then *p++ reads a[1] = 2 (y = 20) and moves p to a[2] = 3. '2 20 1 3' forgets that a[0] itself was incremented.
More C Programming questions
- What is printed? c int x = 10; int p = &x, pp = &p; printf("%d", pp + p 2);
- What is printed? c const char s = " 42, 17"; printf("%zu %zu", strspn(s, " "), strcspn(s, ","));
- A header config.h is wrapped as #ifndef CONFIGH / #define CONFIGH / … / #endif. What problem does this prevent?
- With 4-byte int, after these lines run, which block can no longer be freed because no pointer to it remains? c int a = malloc(10…
- What is printed? c int pal(const char s, int i, int j) { if (i >= j) return 1; if (s[i] != s[j]) return 0; return pal(s, i + 1, j - 1); }…
- With 4-byte int, what is printed? c typedef int Row[3]; Row m[2] = {{1, 2, 3}, {4, 5, 6}}; Row p = m; printf("%zu %d", sizeof(Row)…