9.30.2011

More if-else

Notice the following if statement :
if(expression)
  statement;
Here the expression can any valid expression including a relational expression. We can even use arithmetic expression in the if statement. For example all the following if statement are valid :
if(10 + 5 % 7)
  statement;
if(n=20)
  statement;
if(-15)
  statement;
if(-2.0)
  statement;

In C every expression is evaluated in terms of zero and non-zero values.
Note: that in C a non-zero value is considered to be true, whereas a 0 is considered to be false.
The default scope of the if statement is only the next statement. So, to execute more than one statement they must be written in a pair of braces

No comments:

Post a Comment