O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required