Tuesday, September 21, 2010

Expression Statements

a few special points are
mentioned here. Remember, an expression statement is simply a valid expression
followed by a semicolon, as in
func(); /* a function call */
a = b+c; /* an assignment statement */
b+f(); /* a valid, but strange statement */
; /* an empty statement */
The first expression statement executes a function call. The second is an assignment.
The third expression, though strange, is still evaluated by the C++ compiler because
the function f() may perform some necessary task. The final example shows that a
statement can be empty (sometimes called a null statement).



Block Statements

Block statements are simply groups of related statements that are treated as a unit. The
statements that make up a block are logically bound together. Block statements are also
called compound statements. A block is begun with a { and terminated by its matching }.
Programmers use block statements most commonly to create a multistatement target
for some other statement, such as if. However, you may place a block statement
anywhere you would put any other statement. For example, this is perfectly valid
(although unusual) C/C++ code:
#include <stdio.h>
int main(void)
{
int i;
{ /* a block statement */
i = 120;
printf("%d", i);
}
return 0;
}

No comments:

Post a Comment