Search code examples
c++goto

Valid target for goto statement


I was doing a C++ test and one question puzzeled me a lot.

What is the valid target for goto statement:

  1. &Label;
  2. :LABEL
  3. <LABEL>
  4. Label:
  5. :Label;

I think ; has nothing to do with goto statement. It is a sequence point. So the only one answer would be 5 but <> are not permitted in the label name, I'm very confused.


Solution

  • The correct syntax for the target of goto is

    4) Label:
    

    Though it would be more correctly to say that the target of a goto statement is a label itself because according to the C++ Standard (6.1 Labeled statement)

    The only use of an identifier label is as the target of a goto

    On the other hand the target of a goto statement is a labeled statement.:)

    So in my opinion the question is not clear whether it asks about the syntax of writing a label or what is the target.:).

    I suppose that the question about the syntax.