ProgrammingHardProduct company OA

What is printed?

What is printed?
void move(int **pp) { (*pp)++; **pp += 10; }
int main(void) {
    int a[] = {1, 2, 3};
    int *p = a;
    move(&p);
    move(&p);
    printf("%d %d %d %td", a[0], a[1], a[2], p - a);
}
  1. A. 11 12 3 2
  2. B. 1 12 3 1
  3. C. 1 12 13 0
  4. D. 1 12 13 2

Correct answer: D. 1 12 13 2

Passing &p lets move change the caller's p. Each call first advances p, then adds 10 to the element it now points at: a[1] = 12, then a[2] = 13, and p ends at a + 2. '… 0' assumes the pointer was passed by value.

More C Programming questions

Exams that ask this topic