-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut50.cpp
37 lines (30 loc) · 885 Bytes
/
tut50.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
// Revisiting Pointers: new and delete Keywords in CPP
#include <iostream>
using namespace std;
int main()
{
// Basic example
int a = 4;
int *ptr = &a;
cout << " The value of a is" << *(ptr) << endl;
// new Operator
float *p = new float(40);
cout << " The value at address p is" << *(p) << endl;
int *arr = new int[3];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
cout << "The value of arr[0] is " << *(p) << endl;
cout << "The value of arr[1] is " << *(p) << endl;
cout << "The value of arr[2] is " << *(p) << endl;
// delete Operator
int *arr = new int[3];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
delete[] arr;
cout << "The value of arr[0] is " << arr[0] << endl;
cout << "The value of arr[1] is " << arr[1] << endl;
cout << "The value of arr[2] is " << arr[2] << endl;
return 0;
}