OneBite.Dev - Coding blog in a bite size

use if conditional statement in C

Code snippet on how to use if conditional statement in C

  int age = 16;
  
  if (age > 18) 
  {
      printf("You can drink alcohol");
  } 
  else 
  {
      printf("You cannot drink alcohol");
  } 

This code uses an if-statement to check if the age is greater than 18. If it is greater, then it will output a statement that says “You can drink alcohol” to the user. Otherwise, the code will output “You can’t drink alcohol”. The code first declares an integer called ‘age’ and assigns it a value of 16. The if-statement then checks to see if the age is greater than 18 and if it meets the condition, the code will execute the statement in the if-block. Otherwise, the code will go to the else-block and execute the statement there.

c