ProgrammingHardIBM · Deloitte pattern

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

Assume a 64-bit LP64 ABI. What is printed?
struct Counter {
    int value;
};
void increment(struct Counter *c) {
    c->value++;
}
int main(void) {
    struct Counter counters[3] = {{0}, {10}, {20}};
    for (int i = 0; i < 3; i++) increment(&counters[i]);
    printf("%d %d %d", counters[0].value, counters[1].value, counters[2].value);
}
  1. A. 1 11 21
  2. B. 0 10 20
  3. C. 1 1 1
  4. D. 3 3 3

Correct answer: A. 1 11 21

increment() receives a pointer to each struct and mutates its value member in place through c->value++; each of the three counters is independently incremented by 1 from its initial value: 0->1, 10->11, 20->21.

More C Programming questions

Exams that ask this topic