J
jiing
int main(void){
char* p;
char q[10];
char temp='a'; //This line is outside
for(int i=0;i <10;i++){
p = &temp;
p++;
q='a';
}
for(int i=0;i<10;i++){
cout<<*p++<<"\t";
cout<<q<<endl;
}
}
int main(void){
char* p;
char q[10];
for(int i=0;i <10;i++){
char temp='a'; //This line is inside
p = &temp;
p++;
q='a';
}
for(int i=0;i<10;i++){
cout<<*p++<<"\t";
cout<<q<<endl;
}
}
why their result are not the same?
Can someone explain it for me.
Thanks a lot.
-jiing-
char* p;
char q[10];
char temp='a'; //This line is outside
for(int i=0;i <10;i++){
p = &temp;
p++;
q='a';
}
for(int i=0;i<10;i++){
cout<<*p++<<"\t";
cout<<q<<endl;
}
}
int main(void){
char* p;
char q[10];
for(int i=0;i <10;i++){
char temp='a'; //This line is inside
p = &temp;
p++;
q='a';
}
for(int i=0;i<10;i++){
cout<<*p++<<"\t";
cout<<q<<endl;
}
}
why their result are not the same?
Can someone explain it for me.
Thanks a lot.
-jiing-