C Programming · Question 15 · Hard
What will be the output of the following C program?
#include <stdio.h>
int main(void) {
unsigned int u = 1;
int i = -1;
if (i < u)
printf("less");
else
printf("greater");
return 0;
}
- greater
- less
- Compilation error
- Runtime error
Answer and explanation
Answer: A. greater
Explanation: When an int is compared with an unsigned int, the int is converted to unsigned. -1 becomes 4294967295 (UINT_MAX for 32-bit int), which is larger than 1, so the else branch runs.
Previous: What will be the output of the following C program? · Next: What will be the output of the following C program?
Practise c programming
Try a fresh set of c programming questions with an explanation after every answer, free and without signing up: C Programming practice. Or sit a full placement mock test.
More c programming questions
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
More technical & programming practice
Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge