P
pembed2003
Hi coders,
I have the following:
void f1(char* &s){
*s = 'a';
}
void f2(char* s){
*s = 'b';
}
int main(int argc,char** argv){
char a[] = "1234";
char* b = a;
printf("%s\n",a);
f1(b);
printf("%s\n",a);
f2(b);
printf("%s\n",a);
return 0;
}
The above prints:
1234
a234
b234
My question is:
1. How is char*& different from char* since they both do the same thing?
2. When do you use the first form and the second form?
Thanks!
I have the following:
void f1(char* &s){
*s = 'a';
}
void f2(char* s){
*s = 'b';
}
int main(int argc,char** argv){
char a[] = "1234";
char* b = a;
printf("%s\n",a);
f1(b);
printf("%s\n",a);
f2(b);
printf("%s\n",a);
return 0;
}
The above prints:
1234
a234
b234
My question is:
1. How is char*& different from char* since they both do the same thing?
2. When do you use the first form and the second form?
Thanks!