Labeled statements

There are three kinds of labels: identifier, case, and default.

Read syntax diagramSkip visual syntax diagram
Labeled statement syntax

>>-identifier--:--statement------------------------------------><

The label consists of the identifier and the colon (:) character.

C A label name must be unique within the function in which it appears. C

C++ only In C++, an identifier label can only be used as the target of a goto statement. A goto statement can use a label before its definition. Identifier labels have their own namespace; you do not have to worry about identifier labels conflicting with other identifiers. However, you cannot redeclare a label within a function. C++ only

Case and default label statements only appear in switch statements. These labels are accessible only within the closest enclosing switch statement.

Read syntax diagramSkip visual syntax diagram
case statement syntax

>>-case--constant_expression--:--statement---------------------><

Read syntax diagramSkip visual syntax diagram
default statement syntax

>>-default--:--statement---------------------------------------><

The following are examples of labels:
 comment_complete : ;            /* null statement label */
 test_for_null : if (NULL == pointer)