ProgrammingHardWipro · Cognizant pattern

Assume a 64-bit LP64 ABI. What is printed?

Assume a 64-bit LP64 ABI. What is printed?
struct Point { int x, y; };
void movePoint(struct Point *p, int dx, int dy) {
    p->x += dx;
    p->y += dy;
}
int main(void) {
    struct Point pts[2] = {{0,0}, {10,10}};
    movePoint(&pts[0], 5, 5);
    movePoint(pts + 1, -3, -3);
    printf("%d,%d %d,%d", pts[0].x, pts[0].y, pts[1].x, pts[1].y);
}
  1. A. 5,5 10,10
  2. B. 0,0 7,7
  3. C. 5,5 7,7
  4. D. 0,0 10,10

Correct answer: C. 5,5 7,7

&pts[0] and (pts+1) both correctly pass pointers to the respective struct elements; movePoint mutates them in place through the pointer. pts[0] becomes (0+5, 0+5)=(5,5); pts[1] becomes (10-3, 10-3)=(7,7).

More C Programming questions

Exams that ask this topic