What Happens if the Conditional Expression is Missing in an if Statement?

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.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.