ProgrammingVery hardProduct company OA
What is printed?
What is printed?
const char *w[] = {"heap", "stack", "queue", "trie"};
const char **p = w;
printf("%c", *++*p);
printf("%c", **++p);
printf("%c", *(*p + 3));
printf("%c", (*(p + 1))[4]);
printf(" %s %td", w[0], p - w);- A. hsce heap 1
- B. esce heap 1
- C. etke eap 2
- D. esce eap 1
Correct answer: D. esce eap 1
*++*p increments the pointer STORED in w[0] (it now points at "eap") and reads 'e'. **++p moves p itself to w[1] and reads 's'. *(*p + 3) is the fourth character of "stack", 'c'; (*(p + 1))[4] is "queue"[4] = 'e'. w[0] was permanently advanced, so %s prints eap, and p − w = 1. The strings themselves are never modified – only pointers to them – so this is well defined.
More C Programming questions
- Assume 8-bit unsigned char. What is printed? c unsigned int count = 0; for (unsigned char i = 250; i != 4; i += 3) count++; printf("%u"…
- Assume 32-bit unsigned int and 64-bit unsigned long long. What is printed? c unsigned int a = 0x80000001u; unsigned int b = a 2; int c =…
- Assume a 64-bit LP64 ABI (4-byte int, 8-byte pointers and double, natural alignment). What is printed? c char s[] = "a0bc"; char p = s…
- What is printed? c int inc(int x) { return x + 1; } int dbl(int x) { return x 2; } int sqr(int x) { return x x; } int apply(int…
- What is printed? c int s = 0; for (int i = 0; i < 6; i++) { switch (i % 4) { case 0: s += 1; case 1: s += 2; break; case 2: continue…
- What is printed? c int calls; int f(int n) { calls++; return n < 3 ? n : f(n - 1) + f(n - 3); } int main(void) { int r = f(8); printf("%d…