- C++ Game Development By Example
- Siddharth Shekar
- 168字
- 2021-06-24 14:26:12
Scope of variables
You may have noticed that we have two variables called c in the program right now. There is a c in the main function as well as a c in the add function. How is it that they are both named c but have different values?
In C++, there is the concept of a local variable. This means that the definition of a variable is confined to the local block of code it is defined in. Consequently, the c variable in the add function is treated differently to the c variable in the main function.
There are also global variables, which need to be declared outside of the function or block of code. Any piece of code written between curly brackets is considered to be a block of code. Consequently, for a variable to be considered a global variable, it needs to be in the body of the program or it needs to be declared outside a block of code of a function.
- 新媒體跨界交互設計
- 觸摸屏實用技術與工程應用
- 嵌入式技術基礎與實踐(第5版)
- Artificial Intelligence Business:How you can profit from AI
- 電腦高級維修及故障排除實戰
- Intel Edison智能硬件開發指南:基于Yocto Project
- Blender Quick Start Guide
- Hands-On Artificial Intelligence for Banking
- 無蘋果不生活:OS X Mountain Lion 隨身寶典
- Blender Game Engine:Beginner's Guide
- Hands-On Motion Graphics with Adobe After Effects CC
- 單片機項目設計教程
- Instant Website Touch Integration
- USB應用開發寶典
- 筆記本電腦現場維修實錄