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

In C, the if statement needs a conditional expression to decide whether to execute a block of code. This condition is usually a logical or relational expression that returns either true (non-zero) or false (zero).

Syntax of a valid if statement:

if (condition)
{
    // code to execute if condition is true
}

What If the Condition Is Missing?

If the conditional expression is missing, the C compiler will throw a syntax error. This is because the if statement needs a valid expression to evaluate.

Example – Compilation Error:

advertisement
#include <stdio.h>
 
int main()
{
    if ()  // Missing condition
    {  
        printf("This will cause a compiler error.\n");
    }
    return 0;
}

Error Message:

error: expected expression before ')' token

Correct Example with a Condition:

Free 30-Day Python Certification Bootcamp is Live. Join Now!
#include <stdio.h>
 
int main()
{
    if (1) // Condition present, evaluates to true
    {
        printf("This will execute because the condition is true.\n");
    }
    return 0;
}

You can use any valid expression that evaluates to non-zero (true) or zero (false). Even a constant like 1 (true) or 0 (false) works.

Sanfoundry Global Education & Learning Series – 1000 C Tutorials.

If you wish to look at all C Tutorials, go to C Tutorials.

advertisement

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
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 40s–60s and exploring new directions in your career, I also offer mentoring. Learn more here.