Brackets {} indicate a new scope, so when you do this:
int main(){ { //this bracket is pretty useless const std::string s = "a string"; std::cout << s << std::endl; //should print "a string" { //this creates a new scope const std::string s = "another string"; //s already exists, but in a different scope, so this is legal std::cout << s << std::endl; //should print "another string" } } return 0;}
The second example just adds an additional semi-colon. You can really have as many of these as you want, if you have a line with nothing but a semi-colon on it thats just a NOP, so while it may be bad style, its perfectly legal.
int main(){ { const std::string s = "a string"; std::cout << s << std::endl; { const std::string s = "another string"; std::cout << s << std::endl; } ; //this is a NOP, it won't cause any harm, but it doesn't do any good either } return 0;}
From your original question, it sounds like the book was asking you if either were legal. Were you expecting one to be invalid?