ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
int a = 7;
int r = a % 3 + 2 * a / 7;
printf("%d", r);- A. 4
- B. 3
- C. 9
- D. 1
Correct answer: B. 3
%, * and / share the same precedence level, evaluated left to right. a%3 = 1. 2*a = 14, then 14/7 = 2 (the * happens before the / since they're evaluated left-to-right at equal precedence). r = 1 + 2 = 3.
More C Programming questions
- What is printed? c int a = 5, b = 10; int r = a & b == 10; printf("%d", r);
- What is printed? c char arr[] = {"alpha", "beta", "gamma"}; char p = arr; printf("%s %c %s", (p + 1), ((p + 2) + 1), p);
- What is printed? c int x = 10; int p = &x; int pp = &p; pp = 20; pp = NULL; printf("%d %d", x, (p == NULL));
- What is printed? c void modify(int arr, int n) { for (int i = 0; i < n; i++) arr[i] = 2; } int main() { int a[] = {1, 2, 3}; int p = a…
- What is printed (64-bit, 4-byte int)? c int a[5] = {1,2,3,4,5}; int p = a + 5; printf("%d", (p - 1) + (a + 0));
- What is printed? c int x = 100; void f(int p) { int y = 200; p = &y; } int main() { int p = &x; f(p); printf("%d", p); }