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);
}- A. 1 11 21
- B. 0 10 20
- C. 1 1 1
- 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
- Assume a 64-bit LP64 ABI. What is printed? c struct Pair { int a, b; }; struct Pair swapPair(struct Pair p) { int tmp = p.a; p.a = p.b…
- Assume a 64-bit LP64 ABI. What is printed? c struct Employee { char name[20]; int id; float salary; }; struct Employee e1 = {"Alice", 101…
- Assume a 64-bit LP64 ABI. What is printed? c struct Point { int x, y; }; struct Point make(int a, int b) { struct Point p = {a, b}; return…
- Assume a 64-bit LP64 ABI. What is printed? c typedef struct { int x; int y; } Point; Point p1 = {1, 2}; Point p2 = {1, 2}; printf("%d"…
- Assume a 64-bit LP64 ABI. What is printed? c struct Node { int value; struct Node next; }; struct Node a = {1, NULL}; struct Node b = {2…
- Assume a 64-bit LP64 ABI. What is printed? c struct Point { int x, y; }; struct Point origin = {0, 0}; struct Point p1 = &origin; struct…