ProgrammingHardWipro · Cognizant pattern
Assume 32-bit int. What is printed?
Assume 32-bit int. What is printed?
int x = 3;
int y = 1 << x | 1;
printf("%d", y);- A. 9
- B. 8
- C. 17
- D. 2
Correct answer: A. 9
<< has higher precedence than |, so 1 << x | 1 parses as (1 << x) | 1 = (1 << 3) | 1 = 8 | 1 = 9 (binary 1000 | 0001 = 1001).
More C Programming questions
- Assume 32-bit int. What is printed? c int permissions = 0; #define READ 4 #define WRITE 2 #define EXEC 1 permissions |= READ | WRITE…
- What happens when this runs? c int main(void) { int arr[3]; for (int i = 0; i < 3; i++) { printf("%d ", arr[i]); } }
- What happens when this runs? c void f(int p) { free(p); p = 10; } int main(void) { int x = malloc(sizeof(int)); f(x); printf("done"); }
- What happens when this runs? c int compute(int a, int b) { int result; if (a > b) { result = a - b; } return result; } int main(void) {…
- What happens when this runs? c int makeArray(void) { int local[10]; for (int i = 0; i < 10; i++) local[i] = i; return local; } int…
- What happens when this runs? c int arr[5] = {1, 2, 3, 4, 5}; int p = arr; int val = p[-1]; printf("%d", val);