ProgrammingHardIBM · Deloitte pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
int x = 100;
int y = x / 3 * 3;
int z = x % 3;
printf("%d %d", y, z);- A. 100 1
- B. 99 1
- C. 99 0
- D. 100 0
Correct answer: B. 99 1
Integer division truncates: 100/3 = 33 (dropping the remainder). 33*3 = 99, not 100 — multiplying back doesn't recover the original value because of that truncation. x%3 = 100 mod 3 = 1 (since 99 is the largest multiple of 3 not exceeding 100).
More C Programming questions
- What happens when this runs? c int p = malloc(sizeof(int) 5); if (p) { for (int i = 0; i < 5; i++) p[i] = i; } int q = realloc(p…
- Assume 32-bit int. What is printed? c int arr[5] = {1, 2, 3, 4, 5}; int p = arr; int sum1 = arr[2] + (arr + 2); int sum2 = (p + 2) + p[2]…
- What is printed? c #define SIGN(x) ((x) > 0 ? 1 : (x) < 0 ? -1 : 0) int main(void) { int values[3] = {-5, 0, 7}; for (int i = 0; i < 3…
- Assume a 64-bit LP64 ABI. What is printed? c struct Student { char name[10]; int marks[3]; }; struct Student s = {"Bob", {80, 90, 70}}…
- Assume 32-bit int. What is printed? c int x = 1; int y = 2; int z = 3; int result = x + y == z; printf("%d", result);
- What happens when this runs? c int divide(int result, int a, int b) { if (b == 0) return -1; result = a / b; return 0; } int main(void) {…