117. Write a program to allocate and DE-allocate the memory dynamically? OR write a program to show the use of new and delete operator?

#include<iostream.h>
#include<conio.h>
#define n 3
void main()
{
                int *ptr,i;
                clrscr();
                ptr=new int[n];
                for(i=0;i<n;i++)
                                {
                                cout<<"Enter The Value At "<<i+1<<" Position :- ";
                                cin>>*ptr;
                                ptr++;
                                }
                ptr-=n;
                for(i=0;i<n;i++)
                                {
                                cout<<"The Value At "<<i+1<<" Position = "<<*ptr<<endl;
                                ptr++;
                                }
                delete ptr;
                getch();
}

117.PNG

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: