Wednesday 4 May 2016

Copying the array elements using pointers.

#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],*p,i,b[5],*q;
clrscr();
p=&a[0];
q=&b[0];
cout<<"Enter elements:";
for(i=0;i<5;i++)
{
cin>>*p;
p++;
}
p=&a[0];
for(i=0;i<5;i++)
{
*q=*p;
p++;
q++;
}
q=&b[0];
cout<<"Copied String:";
for(i=0;i<5;i++)
{
cout<<" "<<*q;
q++;
}
getch();
}

No comments:

Post a Comment