ProgrammingVery hardGATE CS · Advanced

What is printed?

What is printed?
struct N { int v; struct N *nx; };

int main(void) {
    struct N c = {3, 0}, b = {2, &c}, a = {1, &b};
    struct N *p = &a;
    p->nx->nx->v += p->v * 10;
    (p = p->nx)->v *= 5;
    printf("%d %d %d", a.v, b.v, c.v);
    return 0;
}
  1. A. 1 2 13
  2. B. 1 10 3
  3. C. 10 10 13
  4. D. 1 10 13

Correct answer: D. 1 10 13

The first statement adds 1 * 10 to c.v (13); then p moves to b and b.v is multiplied by 5, giving 10; a.v is untouched.

More C Programming questions

Exams that ask this topic