File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
Learn_CPP_Programming_Deep_Dive/Section 10 Functions Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ using namespace std ;
4
+
5
+ int global_var = 12 ;
6
+
7
+ void fun ()
8
+ {
9
+ int local_var = 45 ;
10
+ cout<<" Local variable " <<local_var<<endl;
11
+
12
+ global_var++;
13
+ cout<<" The global variable is " <<global_var<<endl; // 13
14
+ }
15
+
16
+ int main (void )
17
+ {
18
+ cout<<" The global variable is " <<global_var<<endl; // 12
19
+ fun ();
20
+ cout<<" The global variable is " <<global_var<<endl; // 13
21
+
22
+ return 0 ;
23
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ using namespace std ;
4
+
5
+ int my_var = 45 ;
6
+
7
+ int main (void )
8
+ {
9
+ int my_var = 70 ;
10
+
11
+ {
12
+ int my_var = 69 ;
13
+ cout<<my_var<<endl; // 69
14
+ }
15
+
16
+ cout<<my_var<<endl; // 70
17
+
18
+ cout<<::my_var<<endl; // 45
19
+ return 0 ;
20
+ }
Original file line number Diff line number Diff line change @@ -8,11 +8,21 @@ int & fun(int &a)
8
8
return a;
9
9
}
10
10
11
+ int fun1 (int b)
12
+ {
13
+
14
+ return 2 *b;
15
+ }
16
+
11
17
int main (void )
12
18
{
13
19
int x = 1953 ;
14
20
15
21
fun (x) = 1954 ;
16
22
23
+ int y = fun1 (3 );
24
+ cout<<" The value of y is " <<y<<endl;
25
+
26
+
17
27
cout<<" The value of x is " <<x<<endl;
18
28
}
You can’t perform that action at this time.
0 commit comments