ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
int x = 2, y = 3, z = 4;
int result = x + y * z - x / y;
printf("%d", result);- A. 14
- B. 7
- C. 20
- D. 13
Correct answer: A. 14
Following standard precedence (* and / before +, -, left to right among equal-precedence operators): x + y*z - x/y = 2 + (3*4) - (2/3) = 2 + 12 - 0 (integer division 2/3 truncates to 0) = 14.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c int arr[5] = {1, 2, 3, 4, 5}; int start = arr; int end = arr + 5; int sum = 0; for (int p =…
- Assume a 64-bit LP64 ABI. What is printed? c int x = 42; void vp = &x; int ip = (int )vp; printf("%d", ip);
- Assume a 64-bit LP64 ABI. What is printed? c int a[3] = {1, 2, 3}; int p = &a[1]; printf("%d %d", p[-1], p[1]);
- Assume a 64-bit LP64 ABI. What is printed? c int x = 5; int p = &x; int pp = &p; pp = NULL; printf("%d", p == NULL);
- Assume a 64-bit LP64 ABI. What is printed? c int a = 10; int p = &a; int q = p; p = NULL; printf("%d %d", p == NULL, q);
- Assume a 64-bit LP64 ABI. What is printed? c int rows = 2, cols = 3; int matrix = malloc(rows sizeof(int )); for (int i = 0; i < rows…