In C, everything is passed by value .
What you pass to fun () is a copy of the pointer that you have in main ().
, ptr , - 115.
ptr main() undefined, .
, fun() :
#include <stdio.h>
#include <stdlib.h>
int* fun(int**);
int main()
{
int a=5;
int* ptr;
fun(&ptr);
a=*ptr;
printf("\n the val of a is:%d",a);
return 0;
}
int* fun(int** another_ptr)
{
*another_ptr = (int*)malloc(sizeof(int));
**another_ptr = 115;
return *another_ptr;
}
, fun() ( ) ptr:
#include <stdio.h>
#include <stdlib.h>
int* fun(int*);
int main()
{
int a=5;
int* ptr;
ptr = fun(ptr);
a=*ptr;
printf("\n the val of a is:%d",a);
return 0;
}
int* fun(int* another_ptr)
{
another_ptr = (int*)malloc(sizeof(int));
*another_ptr = 115;
return another_ptr;
}
: fun(), , , main(). .