Conditionals

Learn how to execute code selectively by using conditional statements formed with the if, else if, and else constructs or the conditional operator.

One of the most important constructs in programming is the ability to execute (or not execute) pieces of code, or execute different pieces of code, depending on the outcome of some decision or question about data. The if-else construct lets us execute code selectively in C based on conditions defined by us.

The if statement

The basic if statement looks like this:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy