An Introduction C++ Statements

By Herbert J. Bernstein

© Copyright, Herbert J. Bernstein, 1999

This is a brief introduction to and summary of C++ Statements. Some portions of the language have been glossed over or omitted here. For more detail, see [Ritchie, 78], [Stroustrup, 86] and [Gehani, 88].

Statements

A C++ program consists of a sequence of statements:

Preprocessor directives

A preprocessor directive begins with the character #. This must either be the first character of the line or the first character of the line after some leading whitespace.

The quoted form of the include searches locally and in standard places for the named file. The bracketed form searches only in standard places.

The constant-expression if an #ifmay include defined(identifier). The #else directive may be used to make alternatives. The #elif allows one #endif to end what are effectively multiple nested else-if clauses.

The #line directive forces an effective change of line number for use by debuggers and can cause confusion.

Preprocessor directives may appear anywhere that the resulting expansion would make sense as C++ code. The preprocessor is run over the entire file before any compilation. The special preprocessor operator "#" causes the expansion of the fillowing identifier to be quoted.

Comments

Comments may be of the form:

     // comment \n

or

      /* comment */

The first form allows a trailing comment on a single line, while the second form allows comments that span multiple lines.

Comments may appear anywhere.

Declarations

Declarations give the compiler informations about the types, storage requirements and intial values of identifiers.

storage_class type identifier intializer;

 

Function Declarations

    storage_class type identifier ( 
        formal_argument_list  ) { 
        function_body }

provides the full definition of a function, while
storage_class type identifier (formal_argument_list);

provides a prototype of a function which may be used to provide code which uses the function with the minimal essential parts of the definition to permit compilation. In the prototype the formal_argument_list must contain the types, but need not contain names for the formal arguments.

In older versions of C, different syntax was used to declare formal arguments, placing them after the closing parenthesis and before the function body.

Executable statements


References

[Ritchie, 78] Ritchie, Dennis M., "The C Programming Language -- Reference Manual", in the "Unix Programmer's Manual, Supplementary Documents", 4.2 Berkeley Software Distribution, Virtual VAX-11 Version, Computer Science Division, Dept. of Electrical Engineering and Computer Science, U. of California, Berkeley, CA, Section 1, March 1984.

[Stroustrup, 86] Stroustrup, Bjarne, "The C++ Programming Language (3rd edition), Addison Wesley Longman, Reading, MA, 1997, ISBN 0-201-88954-4, 920 pp.

[Gehani, 88] Gehani, Narain, "C: An Advanced Introduction (ANSI C Edition)", Computer Science Press, Inc., Rockville, MD, 1988, ISBN 0-7167-8193-X, 265 pp.,



Last Updated on 9 October 1999
By Herbert J. Bernstein
Email:
yaya@bernstein-plus-sons.com