Thursday, 21 September 2017

Add and display data to array using pointer notation

/*
 Insert and display data entered using pointer notation
*/

#include "iostream"
using namespace std;

int main(){
 int arr[5];
 
 cout<<"\nEnter 5 elements \n";
 for(int i=0; i<5; i++){
  cin>>*(arr+i);
 }

 cout<<"\n\nPrinting Array elements";
 for(int i=0; i<5; i++){
  cout<<"\n"<<*(arr+i);
 }
 
        cout<<endl;
}
/*
 OUTPUT
[pavan@localhost PointerArray]$ g++ PointerArray2.cpp
[pavan@localhost PointerArray]$ ./a.out 

Enter 5 elements 
10
20
30
40
50


Printing Array elements
10
20
30
40
50
[pavan@localhost PointerArray]$ 

*/

No comments: