Programming in C

(Barry) #1
8.0 Statements 459

the nullstatement is used to satisfy the requirement that a program statement appear
after the looping expression of the while.

8.9 The returnStatement


One general format for declaring the returnstatement is as follows:
return;
Execution of the returnstatement causes program execution to be immediately
returned to the calling function.This format can only be used to return from a function
that does not return a value.
If execution proceeds to the end of a function and a returnstatement is not encoun-
tered, it returns as if a returnstatement of this form had been executed.Therefore, in
such a case, no value is returned.
A second general format for declaring the returnstatement is as follows:
return expression;
The value of expressionis returned to the calling function. If the type of expression
does not agree with the return type declared in the function declaration, its value is
automatically converted to the declared type before it is returned.

8.10 The switchStatement


The general format for declaring a switchstatement is as follows:
switch ( expression)
{
case constant_1:
programStatement
programStatement
...
break;
case constant_2:
programStatement
programStatement
...
break;
...
case constant_n:
programStatement
programStatement
...
break;
default:
programStatement
programStatement
...
break;
}

20 0672326663 AppA 6/10/04 2:01 PM Page 459

Free download pdf