Code Competitions

Coding competition
Showing posts with label use of pointer as array. Show all posts
Showing posts with label use of pointer as array. Show all posts

Wednesday, 29 May 2013

program to show the use of pointer to show address and elements

#include<iostream.h>
#include<conio.h>
void main()
{
    int num;
    int *ptr,*ptr2;
    ptr=ptr2;
    clrscr();
    cout<<"enter number ";
    cin>>num;
    cout<<"enter the elements ";
    //ptr=ptr2;

    for(int i=0;i<num;i++)
    {
        cin>>*(ptr+i);
    }
    ptr=ptr2;
    //cout<<"num "<<num<<"\taddress "<<&num;
    cout<<"\nentered elements are : ";
    for(i=0;i<num;i++)
    {
        cout<<"\n"<<*(ptr+i)<<"  "<<(ptr+i);
    }
    getch();
}
OUTPUT: