From the course: Complete Guide to C++ Programming Foundations
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Constants - C++ Tutorial
From the course: Complete Guide to C++ Programming Foundations
Constants
- [Presenter] Now, let me tell you a little more about constants in In C++. Constants are identifiers with values that will not change during execution. They are useful as parameters in your code. For example, to set the size of a screen, or the length of a memory buffer. Constants may be implemented with defined directives, or as regular variables. On the one hand, we may create constants with pre-processor directives. The hash defined directive schedules a fine and replace operation so that the code that is sent to the compiler has all the appearances of the defined symbol replaced by its value. These defined symbols are known as macros. Here we have an example to define the number of players in a game as a constant. The player count macro will be replaced with five by the pre-processor everywhere it appears in the source code. Now, you should be aware that the use of hash defined for constants is sometimes discouraged, and considered a bad practice. That's because macros don't have…