ProgrammingVery hardProduct company OA
What is printed?
What is printed?
char *s[] = {"alpha", "beta", "gamma", "delta"};
char **p = s;
p += 2;
printf("%c ", **p);
printf("%c ", *(*(p - 1) + 2));
printf("%s ", *--p + 1);
printf("%c", (*++p)[3]);- A. g t eta m
- B. g t beta m
- C. g e eta m
- D. g t eta a
Correct answer: A. g t eta m
p → "gamma", so **p is 'g'. *(p − 1) is "beta" and +2 gives 't'. *--p moves p back to "beta" and +1 skips one char: "eta". *++p moves p forward to "gamma" again and [3] is 'm'. 'beta' forgets the +1, which applies after the dereference.
More C Programming questions
- What is printed? c int c = 0; int g(int n) { c++; if (n <= 2) return 1; return g(n - 1) + g(n - 2) + g(n - 3); } int main(void) { int r =…
- Assume 32-bit unsigned int. What is printed? c unsigned f(unsigned x) { return (x & 0x55555555u) << 1 | (x >> 1) & 0x55555555u; }…
- What is printed? c #define X 3 #define Y X 2 #if Y == 6 #define Z 1 #else #define Z 2 #endif printf("%d %d", Z, Y + 1 2);
- What is printed? c #define SHOW(x) printf(#x " = %d", x) int a = 3; SHOW(a 2 + 1);
- file1.c contains static int count = 5; at file scope. file2.c contains extern int count; and uses count in main. Nothing else defines…
- What is printed? c int a[] = {10, 20, 30, 40, 50}; int p = (int )(&a + 1); int q = &a[1] + 1; printf("%d %d %td", (p - 1), (q - 1), p - q);