ProgrammingHardTCS NQT · Infosys pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int a = 10;
int *p = &a;
*p += 5;
p = p;
*p *= 2;
printf("%d", a);- A. 15
- B. 30
- C. 25
- D. 20
Correct answer: B. 30
*p += 5 adds 5 to a through the pointer: a becomes 15. `p = p;` is a harmless no-op (self-assignment). *p *= 2 then doubles a through the same pointer: 15 * 2 = 30.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c int a[2][2] = {{1, 2}, {3, 4}}; int p = a[0]; int q = a[1]; printf("%ld", q - p);
- Assume a 64-bit LP64 ABI. What is printed? c int a = 1; int b = 2; int parr[2]; parr[0] = &a; parr[1] = &b; int pp = parr; for (int i = 0…
- What is printed? c void f(int n) { if (n == 0) return; printf("%d ", n); f(n - 1); printf("%d ", n); } int main(void) { f(3); }
- What is printed? c int f(int n, int acc) { if (n == 0) return acc; return f(n - 1, acc n); } int main(void) { printf("%d", f(5, 1)); }
- What is printed? c int f(int n) { int local = n; if (n == 0) return 0; local += f(n - 1); return local; } int main(void) { printf("%d"…
- What is printed? c int f(int n) { if (n == 0) return 1; return n + f(n - 1); } int main(void) { printf("%d", f(100)); }