Course Content
Introduction to C++
To declare a constant, you must specify the const
keyword before the data type of the variable, for example:
If you try to change the value of a constant, the compiler will not allow this to happen and will display the message: "You can't assign to a variable that is const".
This example throws an error. This is done on purpose.
main.cpp
Declaring constants allows you to guarantee that the data in variables is uncharted.
Sometimes, a variable must take on some specific value. For this, enumerations are used. Enumerations allow you to limit the value of a variable to a certain set of allowed values, for example:
main.cpp
When trying to initialize a new variable of the StoreSpace
type with some unknown value, the compiler will generate an error:
This example throws an error. This is done on purpose.
main.cpp
But what happens if we declare variables but do not initialize them?
main.cpp
It is very similar to indexing the array's elements.
main.cpp
If the value of the first element is not specified, then the value will be 0, the value of the second element (if its value is not specified) will be 1, and so on;
But what if the value of the element in the center of the list is given?
main.cpp
Section 2.
Chapter 7