C Language Selection Statements if () ... else statements and syntax

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

While if performs an action only when its condition evaluate to true, if / else allows you to specify the different actions when the condition true and when the condition is false.

Example:

if (a > 1)
    puts("a is larger than 1");
else 
    puts("a is not larger than 1");

Just like the if statement, when the block within if or else is consisting of only one statement, then the braces can be omitted (but doing so is not recommended as it can easily introduce problems involuntarily). However if there's more than one statement within the if or else block, then the braces have to be used on that particular block.

if (a > 1) 
{
    puts("a is larger than 1");
    a--;
}
else 
{
    puts("a is not larger than 1");
    a++;
}


Got any C Language Question?