Code Competitions

Coding competition

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:

No comments:

Post a Comment