From the course: Complete Guide to C++ Programming Foundations
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Using variables - C++ Tutorial
From the course: Complete Guide to C++ Programming Foundations
Using variables
- [Tutor] Let me show you an example of variable declaration and usage for several types. Variable declarations must include the type and name of the variable, and they may include an initialization. So let me go to line seven and declare two integer variables a and b, and let me initialize b to five. Notice that you may declare several variables in one line, separating them with commas. Also, notice that these two variables are at the same level of indentation as the main function. This means that a and b are global variables. Global variables are accessible to all parts of the code. Because of this, the memory for global variables is managed statically by the compiler, so they are allocated in the data segment of memory. Once the program ends, their memory is freed. On the other hand, variables may be local to what is known as their scope. You may declare variables inside functions or inside loops, which de limit their scopes with curly brackets. These variables are accessible in…
Contents
-
-
-
-
Basic data types2m 10s
-
(Locked)
Integer types2m 46s
-
(Locked)
Floating point types1m 29s
-
(Locked)
Variables2m 31s
-
(Locked)
Using variables5m 20s
-
(Locked)
Type aliases3m 58s
-
(Locked)
Enumerations8m 52s
-
(Locked)
Structures3m 13s
-
(Locked)
Type casting6m 18s
-
(Locked)
Type casting examples7m 2s
-
(Locked)
Type inference with auto4m
-
(Locked)
Solution: Data types1m
-
-
-
-
-
-
-
-
-