CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
In this chapter we look at the various ways that the control of flow
statements can be used in a C program, including some statements that
haven't been introduced so far. They are almost always used in conjunction with
logical expressions to select the next action. Examples of logical
expressions that have been seen already are some simple ones used in if
or while
statements. As you might have expected, you can use expressions more
complicated than simple comparison (>
,
<=
,
etc.); what may surprise you is the
type of the result.
All of the examples we have used so far have deliberately avoided using complicated logical expressions in the control of flow statements. We have seen expressions like this
if(a != 100)Example 3.1
Which produces this on its standard output:
value of i is -10, i == 0 = 0, i > -5 = 0In this probably mistaken piece of code, what do you think happens?
The value of b
is
assigned to a
. As you know,
the result has the type of a and whatever value was
assigned to a
. The if will execute the next statement if the value assigned
is not zero. If zero is assigned, the next statement is ignored. So now you
understand what happens if you confuse the assignment with the equality
operator!
In all of the statements that test the value of an expression, the if
, while
, do
, and for statements, the expression is simply tested
to see if its value is zero or not.
We will look at each one in turn.
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 807
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved