Reputation: 13
In C++, I can do this:
#include <stdio.h>
void ChangeAddress(char *¶)
{
char *temp = "123456";
para = temp;
}
int main()
{
char *para = "abcdef";
ChangeAddress(para);
printf("%s\n",para);//123456
return 0;
}
So is there any alternative way in C?
Upvotes: 0
Views: 305
Reputation: 34391
Replace reference with pointer:
#include <stdio.h>
void ChangeAddress(char ** para)
{
char *temp = "123456";
*para = temp;
}
int main()
{
char *para = "abcdef";
ChangeAddress(¶);
printf("%s\n",para);//123456
return 0;
}
Upvotes: 10