ProgrammingHardIBM · Deloitte pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
int x = 10;
int *p = &x;
*p += 5;
*p *= 2;
printf("%d", x);- A. 30
- B. 20
- C. 15
- D. 25
Correct answer: A. 30
Both compound assignments act through the pointer on the real variable x. *p += 5 makes x = 10+5 = 15. *p *= 2 then makes x = 15*2 = 30. Each statement is fully sequenced before the next runs, so there's no ambiguity here.
More C Programming questions
- What happens when this runs? c int fibonacci(int n) { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); } int main(void) {…
- Assume 32-bit int. What is printed? c int arr[3] = {1, 2, 3}; int total = 0; int i; for (i = 0; i < 3; i++) total = total + arr[i]…
- Assume a 64-bit LP64 ABI. What is printed? c int createZeroed(int n) { int arr = calloc(n, sizeof(int)); return arr; } int main(void) {…
- Assume 32-bit int. What is printed? c int x = 5; int y = x-- - --x; printf("%d %d", x, y);
- Assume a 64-bit LP64 ABI. What is printed? c struct Pair { int first; int second; }; struct Pair makePair(int a, int b) { return (struct…
- What is printed? c int main(void) { int a = 10, b = 3; printf("%d %d %f", a / b, a % b, (float)a / b); }