Repository navigation
Expand file tree
/
Copy path07_Pointers_References_Arrays.cpp
More file actions
70 lines (60 loc) · 1.67 KB
/
Copy path07_Pointers_References_Arrays.cpp
File metadata and controls
70 lines (60 loc) · 1.67 KB
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
#include <iostream>
using namespace std;
int main()
{
/*
Derived Data Types:
1. Pointers
2. References
3. Arrays
*/
cout << "Pointers(Address keepers):\nIt is a type of data type which stores address of another data type.\n";
int w = 5;
// data type --> Pointer
// & --> Address of operator
int *v = &w; //Here * is used for making a integer type pointer
cout << "The address of w is " << &w << endl;
cout << "The value of v is " << v << endl;
// * --> Dereferencing Operator
cout << "The value of v is " << v << endl;
cout << "The value of *v = w is " << *v << "\n\n";
cout << "Pointer to Pointer:\n";
// Pointer --> Pointer
int **u = &v;
// Address Check
cout << "The address of v is " << &v << endl;
cout << "The value of u is " << u << endl;
// Dereferencing
cout << "The value of u is " << u << endl;
cout << "The value of *u = v is " << *u << endl;
cout << "The value of **u = w is " << **u << "\n\n";
cout << "Reference Variables: \n";
float p = 25;
float &q = p;
cout << "Value of p is: " << p << ", q(Reference of p) is: " << q << "\n\n";
cout << "Arrays: Allocation of Contiguous(next to each other) Memory Location.\nIt is similar to list in python but have smooth memory access\n";
int marks[] = {10,
20,
30};
marks[3] = 40;
i = 0;
while (i < 4)
{
cout << marks[i] << endl;
i++;
if (i == 4)
{
cout << "\n";
}
}
cout << "Pointers in Arrays:\nWhen we point address of array it is pointed at 0th element of array.\nArray Items are\n";
int *t = marks; // Here we don't use & for addressing
i = 0;
// Arithmetic in pointers
while (i < 4)
{
cout << *(t + i) << endl;
i++;
}
return 0;
}