课程: Complete Guide to C++ Programming Foundations
免费学习该课程!
今天就开通帐号,24,100 门业界名师课程任您挑!
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…