Search This Blog

Pages

Wednesday, January 12, 2011

Storing numbers dynamically n displaying them


/*
 * storing_numbers_dynamically_n_displaying_them.cpp
 *
 *  Created on: Jan 12, 2011
 *      Author: bgsudeep
 *      
 *      Here "dynamically" means a pointer with delete option
 *      We should have to store the numbers using a pointer in main function and at the end of the
 *      program we should have to clean or delete the memory used by the program.
 */

#include<iostream.h>
int main()
{
int *p=new int[10];
int i;
for(i=0;i<10;i++)
{
cout << "Enter a number: ";
cin >> *(p+i);
}
cout<<"You have entered the numbers:";
for(i=0;i<10;i++)
{
cout <<  *(p+i) << endl;
}
delete []p; //here delete is used to remove all the memory allocations used by the program.
return 0;
}

No comments:

Post a Comment