Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Chapter 2. Directing Program Flow > Using the if Statement - Pg. 26

Chapter 2 Using the if Statement The if statement is the most basic of the program flow control statements. This state- ment lets you test a condition, and if the con- dition is true, lets you execute specific code. temperature to 72, you can use an if state- #include<stdio.h> intmain(void) { inttemperature=72; if(temperature= =72) { . . . } return0; } For example, if you set a variable named ment to test to make sure that the variable does contain 72. You place the condition you want to test, which in this case is temperature = =72 , using the = = equality operator, inside parentheses, and the code you want to exe- cute if the condition is true in curly braces following the parentheses, like this: #include<stdio.h> intmain(void) { inttemperature=72; if (temperature = = 72) Listing 2.1 Starting if.m. #include<stdio.h>