If Statements

Conditionals are a branching type of control structure, meaning they dictate the course of an application based on certain parameters. Of the branching control structures, the if conditional is the most common. Its syntax is straightforward:

if (condition) {
   statements;
}

The condition is placed within parentheses, followed by—within curly braces—the statement or statements to be executed. If the condition is true, the statements will be executed. If it is false, the statements will not be run.

In C, the simplest representation of false is the number 0 and true is everything else:

if (1) {
   printf ("This conditional is always

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.