int main()
{
int x=5,y=5;
int sum = add(&x,&y);
cout<<"Address of x is"<<&x<<endl;
cout<<"Address of y is"<<&y<<endl;
cout<<"The addition of a and b is"<<sum<<endl;
int a[5]={1,2,3,4,5};
int *p1;
p1=a;
for(int i=0;i<5;i++)
{
cout<<"The Address of the Array elements is"<<p1+i<<endl;
cout<<"The value of the array element is"<<*(p1+i)<<endl;
}
cout<<endl;
cout<<endl;
for(int i=0;i<5;i++)
{
cout<<"The Address of the Array elements is"<<&p1[i]<<endl;
cout<<"The value of the array element is"<<p1[i]<<endl;
}
cout<<"address of a is "<<p1<<endl;
int arrayTotal= SumofArray(a,5);
cout<<"The sum of array is"<<arrayTotal <<endl;
}
I started to learn to code and I believe, I have to be strong with pointers to code in c++ and make efficient programs.
when we assign p1=a;
Literally i can use a[i] or p[i]? I am confused between this difference. The above snippet works tho I am curious if some one can explain in detail.
Thanks