ProgrammingVery hardGATE CS · TCS NQT
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
printf("%d", sizeof(char) - 2 > 0);
}- A. 0
- B. 2
- C. 3
- D. 1
Correct answer: D. 1
sizeof yields an unsigned size_t, so sizeof(char) - 2 wraps to a huge value, which is greater than 0. Assuming a signed result would give 0.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int a[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4}; int best = a[0], cur = a[0]; for (int i…
- How many subarrays of {1, -1, 2, -2, 3} have sum zero? Compute with this program. c #include <stdio.h> int main(void) { int a[] = {1, -1…
- What is printed? c #include <stdio.h> int pc(unsigned n) { return n ? (int)(n & 1u) + pc(n >> 1) : 0; } int main(void) { printf("%d"…
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (13 << 1) + 13); }
- How many numbers from 1 to 100 are multiples of 16? Compute with this program. c #include <stdio.h> int main(void) { int c = 0; for…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 1u << 31; x <<= 1; printf("%u", x); }