Explain IF-Else Statement in C Language ?

  • If statement in C is known as a decision-making statement.
  • It makes a decision based on the condition given.
  • It is followed by an optional else statement.
  • The block of codes inside the if statement is executed only if the given condition is true.
  • Codes inside the curly braces are skipped if the condition evaluates to false, and the code after the if statements are executed.
  • Code inside parenthesis of the if statement is true, everything within the curly braces is executed.
  • If condition true evaluates to true, code runs the printf execution.

Syntax

[pastacode lang=”c” manual=”if%20(testCondition)%20%7B%0A%20%20%20%2F%2F%20statements%0A%7D%0A” message=”” highlight=”” provider=”manual”/]

Sample Code

[pastacode lang=”c” manual=”%23include%20%3Cstdio.h%3E%0A%23include%20%3Cstdbool.h%3E%0A%0Aint%20main(void)%20%7B%0A%20%20%20%20if(true)%20%7B%0A%20%20%20%20%20%20%20%20printf(%22Statement%20is%20True!%5Cn%22)%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20return%200%3B%0A%7D%0A” message=”” highlight=”” provider=”manual”/]

Output

[pastacode lang=”c” manual=”Statement%20is%20True.” message=”” highlight=”” provider=”manual”/]

if..else statements

  • In an ..else statement, code inside the brackets is executed only if the statement condition evaluates to true.
  • If the condition in the if statement evaluates to false, the code inside the else statement is executed.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like