The question is to find the output of the following program:
#include <iostream>
using namespace std;
int main() {
int arr[]={6,3,8,10,4,6,7};
int *ptr=arr,i;
cout<<++*ptr++<<'@';
i=arr[3]-arr[2];
cout<<++*(ptr+i)<<'@'<<'\n';
cout<<++i+*ptr++<<'@';
cout<<*ptr++<<'@'<<'\n';
for(;i>=0;i-=2)
cout<<arr[i]<<'@';
return 0;
}
The output for the above program is:
7@11@
6@8@
11@3@
I know when a pointer is used like this : *ptr=&var;
it stores the address of the variable var
in the pointer variable ptr
.
These are my questions:
What does
*ptr=arr[];
do? Whereptr
is declared as an integer andarr
is an integer array?What does
*ptr=a;
do ifptr
anda
are declared as integer variables?