왜 이럴까요?

익명 사용자의 이미지

#include
#include

void test(int **t1){
int *p;
p=(int *)malloc(sizeof(int));
*p=1;
*t1=p;
}

main()
{
int *t;
test((int **)&t);
printf("%d",*t);
free(t);
}
//잘돌아감....
*/

/*

#include
#include
void test(int *t1){
int *p;
p=(int *)malloc(sizeof(int));
*p=1;
t1=p;

}
main()
{
int *t1;
// t1=malloc(4);
test(t1);
printf("%d",*t1);
free(t1);
}
//안돌아감..

*/

/*
#include
#include

void test(int **t1){
int *p;
p=(int *)malloc(sizeof(int));
*p=1;
*t1=&p;
}

main()
{
int **t;
test(t);
printf("%d",**t);
free(t);
}

//안돌아감...
*/

아래거 2개가 왜 안돌아가는 지궁금합니다..
맨위에것이 돌아가면 돌아가야 될거 같은데..
재생각에는 돌아가야 정상일거같은데..

왜안될까요...

익명 사용자의 이미지

c함수는 call by value이기때문에 call하는 함수(caller)안에 있는
변수의 내용을 call되는 함수(callee)에서 변경하려면 변수의address
를 전달해야 됨.