1 #include<iostream>
2 /* Creating a array dynamically*/
3 using namespace std;
4 int main()
5 {
6 int *a;/* Creating a pointer*/
7 int *c;
8 int b,sz;
9 sz=0;
10 char choice;
11 cout<<"Do you want to create a new array "<<endl;
12 cin>>choice;
13 if(choice=='y' || choice=='Y')
14 a = new int;/* First free memory assigned to the pointer*/
15 else
16 {
17 cout<<endl<<"You are exiting the program";
18 return 0;
19 }
20
21 c=a;
22 while(1)
23 {
24 cout<<"Do you want to add an element to the existing array "<<endl;
25 cin>>choice;
26 if(choice=='y' || choice=='Y')
27
28 {
29 cout<<" Enter the value ";
30 cin>>b;
31 cout<<a<<endl;
32 *a=b;
33 sz++;
34 cout<<*a<<endl;
35 }
36
37 else
38 break;
39 a++;
40
41 }
42 cout<<"Reading it"<<endl;
43 for(int j=0;j<sz;j++)/* Reads array backwards*/
44 {
45 cout<<*c<<endl;
46 c++;
47 /* To read it from start,store starting address in new variable*/
48
49 }
50 }