指针传递参数,有点不理解了
测试一下形参,但是有了新的疑惑。主函数输出的乱码,和out函数输出竟然不一致,我明明传指针进去的啊程序代码:
#include<stdio.h> #include<string.h> char *Get1() { char a[8]; scanf("%s", a); printf("Get :%s\n", a); return a; } char *Get2() { char a[] = "dfhbdh"; printf("Get :%s\n", a); return a; } char *Get3() { char *a = "dfhbdh"; printf("Get :%s\n", a); return a; } void Out(char *a) { printf("Out :%s\n\n", a); } int main() { char *s1 = Get1(); printf("Main:%s\n", s1); Out(s1); char *s2 = Get2(); printf("Main:%s\n", s2); Out(s2); char *s3 = Get2(); printf("Main:%s\n", s3); Out(s3); return 0; }