ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
int flag = 0, mask = 2;
flag |= mask == 2;
printf("%d", flag);- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
== has higher precedence than |=, so this is flag |= (mask == 2). mask == 2 is 1, so flag becomes 0 | 1 = 1.
More C Programming questions
- What is printed? c int a = 1, b = 2, c = 3; int arr[3] = {&a, &b, &c}; int p = arr; for (int i = 0; i < 3; i++) { (p + i) = 10; }…
- What is printed? (undefined behavior aside, assume typical stack layout where locals of adjacent calls can overlap after return) c int…
- What is printed? c char arr[] = {"one", "two", "three"}; char p = arr; printf("%s %c %s", p, ((p + 1) + 1), p[2]);
- What is printed? Assume 32-bit int. c int flags = 0; flags |= (1 << 2); flags |= (1 << 4); flags &= ~(1 << 2); printf("%d", flags);
- What can be said about this program? c #include <stdlib.h> int main(void) { int p = malloc(sizeof(int)); free(p); free(p); }
- What is printed? c void modify(int arr[10]) { printf("%lu ", sizeof(arr)); } int main(void) { int a[10]; printf("%lu ", sizeof(a))…