C++ Syntax: {..}
Description
Curly braces are used to delimit a
compound statement
For example:-
if ( a > b ) {
float_t temp = b;
b = a;
a = temp;
}
Usage Notes
Compound statements allow the programmer to introduce
a set of statements where the language syntax requires
there only to be one.
The {..} is also central to the idea of
scope
In the example above, the variable temp was defined within the compound
statement following the if; once execution leaves this compound
statement the variable "goes out of scope" and is destroyed.
Sometimes {..} is used to purely allow scratch variables to be created for
short term work; it helps to follow one of the golden rules of programming:-
Keep it Local!
Go Back to the
The C++ Crib Top Page
If you have any comments about this page please send them to
Nick West