example1_basic_code_block.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

int main() {
    int x = 10;
    
    if (x > 5) {
        std::cout << "x is greater than 5" << std::endl;
        x -= 5;
    }
    
    {
        int y = 20; // y is only accessible within these braces
        std::cout << "y = " << y << std::endl;
    }
    
    // std::cout << y << std::endl; // This would cause a compilation error
    
    return 0;
}
Back to curly_brackets