Discussion
What will be the output of the program?
#include <stdio.h>
int main()
{
char str[]="C-program";
int a = 5;
printf(a >10?"Ps\n":"%s\n", str);
return 0;
}
Answer: A
Correct answer: C-program
The conditional operator chooses between the two format strings, not between two outputs. Since \(5 > 10\) is false, the format used is "%s\n", and str is the argument it consumes - so the program prints C-program. Had the condition been true, "Ps\n" would have been the format and str an unused extra argument.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development