Expression

Comma expression is a series of expressions separated by commas. These expressions are evaluated from left to right. The result of a comma expression is the value of the rightmost expression. In the following example, the value of the first comma expression is ix; the value of the second is 0.

// ia, sz, and index are defined elsewhere ...
int ival = (ia != 0)
           ? ix=get_value(), ia[index]=ix
           : ia=new int[sz], ia[index]=0;

For % operator, When both operands are positive, the result is positive. If either (or both) operand is negative, however, the sign of the remainder is machine-dependent.


The simplest form of program statement is the empty, or null, statement. Often in loop body. An empty compound statement is equivalent to a null statement.
; // null statement
{} // equivalent of null statement
The accidental presence of a superfluous null statement does not generate a compile-time error.
i = d + s;; // ok: superfluous null statement

In the 1970s, computer program language design philosophy emphasized the virtue of defining all objects at the start of the program, function or statement block prior to any program statements. (In C, for example, the definition of an object is not treated as a language statement and all object definitions within a block must appear before any program statements. By necessity, C programmers habituate themselves to defining all objects at the top of each current block.) In part, this was a reaction to an error-prone idiom of object definition on-the-fly supported by FORTRAN.

In C++, because the definition of an object is a statement of the language, object definitions in general can be placed anywhere that the other statements of the language can appear. Syntactically, this is what makes locality of declaration possible.

For the built-in types, such as integers and floats, loçality of declaration is primarily a matter of personal preference. The language encourages it by allowing declarations to occur within the condition part of the if, else-if, switch, while, and for loop. Those who favor locality of declaration believe that it makes for more easily understood programs.

Locality of declaration becomes necessary with the definition of class objects with associated constructors and a destructor. When place these class objects at the beginning of a function or statement block, two things happen:
  1. The associated constructors of all the class objects are invoked prior to doing anything within the function or statement block itself. Locality of declaration allows us to amortize the cost of initialization across the extent of the function or statement block.
  2. Perhaps more important, a function or statement block often terminates prior to the execution of every program statement within it. Defining class objects prior to successfully passing those termination points results in the execution of unnecessary constructor-destructor pairs. Given enough class objects or computationally expensive constructors and destructors, unnecessarily impact the run-time efficiency of program. (This is why expert C programmers, with the habit of placing object definitions at the start of functions and statement blocks, may sometimes find their C++ programs performing with less efficiency than equivalent programs written in C.)

Placement of a declaration statement associated with a case or default label is illegal unless it is placed within a statement block. For example, the following results in a compile-time error:
case illegal_definition:
  string s = get_file_name(); // error: declaration must within statement block
  // ...
  break;
If the definition not enclosed within a statement block, it would be visible across case labels but initialized only if the case label within which it is defined is executed. Requiring a statement block ensures that the name is visible and therefore can be used only where it is guaranteed to have been initialized.
case ok:
{
  string file_name = get_file_name(); // ok: declaration within statement block
  // ...
  break;
}
Index