When is a semicolon after } mandated in C++ Program?

C++ProgrammingObject Oriented Programming

A semicolon after a close brace is mandatory if this is the end of a declaration. In case of braces, they have used in declarations of class, enum, struct, and initialization syntax. At the end of each of these statements, we need to put a semicolon. For example,

class X {};    // same declaration for struct as well
enum Y {};
int z[] = {1,2};

A semicolon by itself is an empty statement, and you'll be able to add additional ones anywhere a statement is legal. Therefore it might be legal to place a semicolon right after the braces following your if, although it wouldn't be related to them if at all.

raja
Published on 15-Feb-2018 17:28:33
Advertisements