Question: What is the output for the following code snippet? Will the program get compiled? If not, can you correct the condition in the if statement?
if (;) printf("empty statement ; is considered true!"); else printf("empty statement ; is considered false");
Answer: COMPILATION ERROR! Well! if the empty statement ” ; ” in the if statement is placed in the character literals ‘ ‘, program will compile and run successfully to display the first massage. Reason is characters are INTEGERS INTERNALLY. ; has decimal value 59 in ASCII Character Set. So, the working code would be:
if (';') printf("empty statement ; is considered true!"); else printf("empty statement ; is considered false");
Sanfoundry Global Education & Learning Series – 1000 C Tutorials.
If you wish to look at all C Tutorials, go to C Tutorials.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Buy C Books
- Apply for C Internship
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos
- Buy Computer Science Books