这个题为什么是单项值传递?
#include <stdio.h>#include <string.h>
char fun(char *s){
char a[7];
s=a;
strcpy(a,"look");
}
int main(){
char *p=NULL;
fun(p);
puts(p);//输出的是一个不确定的值
return(0);
}
#include <stdio.h> int main( void ) { puts( NULL ); }
#include <stdio.h> void foo( int x ) { printf( "地址%p处的int变量值为 %d\n", &x, x ); x = 123; printf( "地址%p处的int变量值为 %d\n", &x, x ); } int main( void ) { int a = 1; printf( "地址%p处的int变量值为 %d\n", &a, a ); foo( a ); printf( "地址%p处的int变量值为 %d\n", &a, a ); }
#include <stdio.h> void foo( int* x ) { printf( "地址%p处的int变量值为 %d\n", x, *x ); *x = 123; printf( "地址%p处的int变量值为 %d\n", x, *x ); } int main( void ) { int a = 1; printf( "地址%p处的int变量值为 %d\n", &a, a ); foo( &a ); printf( "地址%p处的int变量值为 %d\n", &a, a ); }
char* fun(char *s){ char* a = (char*)malloc(sizeof(char) * 7);//动态分配内存 s=a; strcpy(a, "look"); return s; } int main(){ char* p = fun(p); puts(p); delete []p; return 0; }