N
nair SL
I want to understand whether this following piece of code is giving me
junk result becoz I'm trying to access values out of scope?
int* array_display(){
int array1[4] = {11,22,33,44};
int *qq = array1;
return qq;
}
int main()
{
int *pp;
pp = array_display();
for(i=0; i<4; ++i,++pp) {
int temp = *(pp); //case 1
// int temp = *(pp+1); //case 2 returns 22 first and
subsequent junk
cout<<"pp array ->- "<<temp<<endl;
}
return 0;
}
expected output : 11 22 33 44
but I'm hitting ony the first access point. Rest is giving me junk.
The point is if I can access any values by incrementing pointer (as in
the second case), why I could not access them a second time?
Any help will be appreciated.
Thanks in advance...
junk result becoz I'm trying to access values out of scope?
int* array_display(){
int array1[4] = {11,22,33,44};
int *qq = array1;
return qq;
}
int main()
{
int *pp;
pp = array_display();
for(i=0; i<4; ++i,++pp) {
int temp = *(pp); //case 1
// int temp = *(pp+1); //case 2 returns 22 first and
subsequent junk
cout<<"pp array ->- "<<temp<<endl;
}
return 0;
}
expected output : 11 22 33 44
but I'm hitting ony the first access point. Rest is giving me junk.
The point is if I can access any values by incrementing pointer (as in
the second case), why I could not access them a second time?
Any help will be appreciated.
Thanks in advance...