forked from codebloded/BackToBasics.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoreOnPointers.cpp
More file actions
31 lines (23 loc) · 842 Bytes
/
moreOnPointers.cpp
File metadata and controls
31 lines (23 loc) · 842 Bytes
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
#include<iostream>
using namespace std;
int main()
{ //Pointers baisc
int x = 56;
int *ptr = &x;
cout<<"The value x is at ptr is :"<<*(ptr)<<endl;
cout<<"The address of x is :"<<(ptr)<<endl;
//new keyword is use for dynamic allocation of memory to the varibles
int *m = new int(56);
cout<<"The value of m is "<<*(m)<<endl;
cout<<"The addres of m is:"<<m<<endl;
//Dyanamic memory alloction in an array usng new keyboard
int *arr = new int[2];
arr[0] = 10;
arr[1]= 56;
//delete keyword is used to delete the all dynamic allocation to the variable and arrays , after delete the memory allocation the variable fills itself with the garbage value;
delete[] arr;
cout<<arr[0]<<endl;
cout<<arr[1]<<endl;
cout<<"The address of arr "<<(arr)<<endl;
return 0;
}