-
Notifications
You must be signed in to change notification settings - Fork 0
/
lec25_pointers.cpp
102 lines (74 loc) · 1.77 KB
/
lec25_pointers.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
#include <iostream>
using namespace std;
int main()
{
int num = 5;
cout << "Num is" << num << endl;
// Adress of variable - &
cout << "Address of num is: " << &num << endl;
int *ptr = # // Pointer
cout << "cout<<ptr is " << ptr << endl;
cout << "cout<<*ptr is " << *ptr << endl;
cout << endl;
double d = 4.2;
double *p2 = &d;
cout << "Num is" << num << endl;
cout << "cout<<p2 is " << p2 << endl;
cout << "cout<<*p2 is " << *p2 << endl;
cout << endl;
cout << "size of int is " << sizeof(num) << endl;
cout << "size of pointer ptr is " << sizeof(ptr) << endl;
cout << "size of double is " << sizeof(d) << endl;
cout << "size of pointer p2 is " << sizeof(p2) << endl;
return 0;
}
*/
/*
#include <iostream>
using namespace std;
int main()
{
// Pointer to int is created and pointing to some garbage address
// int *p=0;
// cout<<*p;
int i = 5;
int *q = &i;
cout << q << endl;
cout << *q << endl;
int *p = 0;
p = &i;
cout << p << endl;
cout << *p << endl;
return 0;
}
*/
#include <iostream>
using namespace std;
int main()
{
int num = 5;
int a = num;
a++;
cout <<"Before " <<num<<endl;
int *p=#
(*p)++;
cout<<"After "<<num<<endl;
int *q=p; //COPYING A POINTER
cout<<" P "<<p<<endl;
cout<<" q "<<q<<endl;
cout<<" *p "<<*p<<endl;
cout<<" *q "<<*q<<endl;
//IMP concept
int i=3;
int *t=&i;
//cout<<(*t)++<<endl;
*t=*t+1;
cout<<*t<<endl;
cout<<"Before t=t+1 t:: "<<t<<endl;
t=t+1;
cout<<"After t=t+1 t:: "<<t<<endl;
cout<<"Ater t=t+1 *t::"<<*t<<endl;
cout<<"Value of i after t=t+1 :: "<<i<<endl;
return 0;
}