4  Data Types

4.1 Introducing New Types

Enum

enum Color = {RED, BLUE, GREEN}

Struct

4.2 Const-Correctness

Marks something that can’t be modified.

include <iostream>

int main(int argc, char const *argv[])
{
    int n = 5;
    const int j = 4;
    const int &k = n; //k can't be modified, equivalently n can't be modified over k
    n++; //but this changes n and indirectly k (because k references n)
    

    const int *p1 = &n; // modifiable pointer to const int 
    int const *p2 = &n; // same thing
    int *const p3 = &n; // constant pointer to modifiable int

    // p1 = &j -- ok
    // *p1 = 3 -- not ok! 
    // p3 = &j -- not ok
    // *p3 = 10 -- ok

    std::cout << "n: " << n << std::endl
              << "j: " << j << std::endl
              << "p1: " << p1 << std::endl
              << "p2: " << p2 << std::endl
              << "p3: " << p3 << std::endl;
    
    
    return 0;
}