怎么通过子函数改变参数指向的地址
void p_add(unsigned char *pt){ pt = pt + 1;}int main(){ unsigned char s[3] = {1, 2, 3}; unsigned char *p; p = s; printf("p = %d\n", *p); p_add(p); printf("p = %d\n", *p); return 0;}
unsigned char *p_add(unsigned char *pt){ pt = pt + 1; return pt;}int main(){ unsigned char s[3] = {1, 2, 3}; unsigned char *p; p = s; printf("p = %d\n", *p); p = p_add(p); printf("p = %d\n", *p); return 0;}
void p_add(unsigned char **pt){ unsigned char *pt1; pt1 = *pt; pt1 = pt1 + 1;}int main(){ unsigned char s[3] = {1, 2, 3}; unsigned char *p; p = s; printf("p = %d\n", *p); p_add(&p); printf("p = %d\n", *p); return 0;}
#include<stdio.h>void p_add(unsigned char **pt){ unsigned char **pt1; pt1 = pt; *pt1 = *pt1 + 1;}int main(){ unsigned char s[3] = {1, 2, 3}; unsigned char *p; p = s; printf("p = %d\n", *p); p_add(&p); printf("p = %d\n", *p); return 0;}
[解决办法]
void p_add(unsigned char **pt)
{
(*pt)++;
}
int main()
{
unsigned char s[3] = {1, 2, 3};
unsigned char *p;
p = s;
printf("p = %d\n", *p);
p_add(&p);
printf("p = %d\n", *p);
return 0;
}