C++20 sections · 1024 units
Open in Course

Curly Braces

Grouping statements together

Curly braces {} group statements into blocks. The main function braces contain all the code that runs when the program starts. Everything between { and } belongs to that function.

Try deleting the opening { after main(). The compiler shows an error because it does not know where the function body starts. Braces define scope. Every opening brace needs a closing brace.

Later you will use braces with if statements and loops. Count them carefully as programs grow larger.