HPlogo HP-UX/HP C Compiler: HP C/HP-UX Reference Manual > Chapter 6 Statements

Expression and Null Statements

» 

Technical documentation

Complete book in PDF

 » Table of Contents

Syntax

expression-statement ::=
[expression];

Description

C expressions can be statements. A null statement is simply a semicolon by itself.

You can use any valid expression as an expression statement by terminating it with a semicolon. Expression statements are evaluated for their side effects such as assignment or function calls. If the expression is not specified, but the semicolon is still provided, the statement is treated as a null statement.

Null statements are useful for specifying no-operation statements. No-operation statements are often used in looping constructs where all of the work of the statement is done without an additional statement.

Example

A program fragment that sums up the contents of an array named x containing 10 integers might look like this:

  for(i=0,s=0; i<10; s+=x[i++]);

The syntax of the “for ” statement requires a statement following the closing ) of the for. A null statement (;) satisfies this syntax requirement.

© Hewlett-Packard Development Company, L.P.