ProgrammingHardGATE CS
What is printed? Assume int and unsigned int are 32 bits.
What is printed? Assume int and unsigned int are 32 bits.
#include <stdio.h>
int main(void) {
int a = -1;
unsigned int b = 1;
printf("%d %d %d", a < b, a < (int)b, (long long)a < (long long)b);
return 0;
}- A. 0 1 1
- B. 1 0 0
- C. 0 0 1
- D. 1 1 1
Correct answer: A. 0 1 1
In a < b the int is converted to unsigned, becoming 4294967295, which is not less than 1, so the first result is 0. With an explicit int conversion, or comparing as long long, the comparison is -1 < 1, which is true.
More C Programming questions
- What is the value printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = 0xB6D9 ^ 0x00FF; int n = 0…
- What is printed? c #include <stdio.h> #define MAX(a, b) ((a) > (b) ? (a) : (b)) int main(void) { int i = 3, j = 5; int m = MAX(i++, j++)…
- What is printed? c #include <stdio.h> int f(int n) { static int c = 0; c++; if (n >= 2) { f(n - 1); f(n - 2); } return c; } int main(void)…
- What is printed? Assume pointers are 8 bytes and the string literal's characters are those between the quotes. c #include <stdio.h>…
- What is the exact output? c #include <stdio.h> int main(void) { int n = printf("%d%d", 12, 345); printf("|%d", n); return 0; }
- What is printed? Assume int is 4 bytes and pointers are 8 bytes. c #include <stdio.h> void f(int a[10]) { printf("%zu ", sizeof a); } int…