ProgrammingModerateTCS NQT · Wipro
What is printed? Assume int is 32 bits and integer division truncates toward zero.
What is printed? Assume int is 32 bits and integer division truncates toward zero.
#include <stdio.h>
int main(void) {
int v[] = {-7, 2};
printf("%d", (v[0] + v[1]) / 2);
}- A. -3
- B. -2
- C. -1
- D. -5
Correct answer: B. -2
The sum is -5, and dividing by 2 truncates toward zero to -2, not the floor -3. Floor division is a common assumption that gives the wrong answer here.
More C Programming questions
- What is the maximum value of depth printed? c #include <stdio.h> int depth = 0, maxd = 0; void r(int n) { depth++; if (depth > maxd) maxd…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3, 4, 5}; int p = a + 2; printf("%d %d", p[-1], p[2]); }
- What is printed? Assume uint32t is 32 bits. c #include <stdint.h> #include <stdio.h> uint32t rotl(uint32t x, unsigned k) { return (x << k)…
- What is printed? c #include <stdio.h> int main(void) { unsigned u = 1; int s = -2; printf("%d %d", s < u, s + (int)u > -2); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { int i = 1; sizet n = sizeof(i++); printf("%d %zu", i, n); }
- How many factors of 2 does 100! contain? Compute with this program. c #include <stdio.h> int main(void) { int c = 0; for (int i = 2; i <=…