-
Notifications
You must be signed in to change notification settings - Fork 0
/
Episode_2_Variables.cpp
68 lines (47 loc) · 1.76 KB
/
Episode_2_Variables.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Episode 2 : Variables
Variable
- used tp store data
- to use variables in C++, you first must declare them in your code !
- By declaring a variable, you are reserving space in the computer's memory fpr it
*/
#include <iostream>
// Variable Declaration
int main(){
int variable = 120;
int a = 5;
int b = 4;
int sum = a + b + variable;
int product = a * b * variable;
std::cout << a; // 5
std::cout << std::endl;
std::cout << sum; // 129
std::cout << std::endl;
std::cout << product << std::endl; // 2400
std::cout << "The sum : " << sum << ", The product : " << product << std::endl;
// This will print The sum : 129, The product 2400
return 0;
}
/*
--------------------------------------------------------------------------
Part 1 : int a = 5;
int : Data type
a : Variable Name
= : Assignment Operator
number 5 : By giving 5 to variable, you are initializing it!
int a = 5; : Initialized
int a; : Uninitialized
--------------------------------------------------------------------------
Part 2 : Arithmetic Operator
Addition Operator : + (plus)
Subtraction Operator : - (minus)
Multiplication Operator : * (time)
Division Operator : / (divided by)
--------------------------------------------------------------------------
Summary
- You declare variables in code
- A variable with a given value is initialized
- Declaring a variable = reserve space in memory
- You can add/subtract/multiply/divided with arithmetoc operator
- Print to the terminal like: std::cout << a
*/