HELP! im looking for different ways .
Im looking for ways to use arrays using pointers.
an ex is:
#include<iostream.h>
#include<conio.h>
void main ()
{
int sales[7]= {1,2,3,4,5,6,7}
int*p=&sales[0];
int x;
//-----------------------------
for(x=0; x<7; ++x)
cout<<"$"<<sales[x]<<" ";
cout<<endl;
//-----------------------------
for(x=0; x<7; ++x)
cout<<"$"<<p[x]<<" ";
cout<<endl;
//-----------------------------
for(x=0; x<7; ++x)
cout<<"$"<<*(sales+x<<" ";
cout<<endl;
//-----------------------------
for(x=0; x<7; ++x)
cout<<"$"<<*(p+x)<< " ";
cout<<endl;
getch();
}
\\ all of the above give the same result
\\$1 $2 $3 $4 $5 $6 $7
any more ways???????
at least I need 10 more ways
any feed back is greatly accepted
Re: HELP! im looking for different ways .
Quote:
Originally posted by moenia
Im looking for ways to use arrays using pointers.
an ex is:
int num[5]={2,6,9,2,2};
int*ptr;
ptr=num;
ptr=&num[0]
any feed back is greatly accepted
congrats, you just ruined your pointer.
Code:
int num[5] = {2, 6, 9, 2, 2};
int *ptr = num[1];
cout<<ptr;
output :