In main
you have to allocate spaces for x
and y
before you can use it. If x
and y
are not allocated spaces, they point to arbitrary memory locations. If they are outside of your program segment, you will get a segmentation fault.
main(){ int* x=malloc(sizeof(int)); *x = 3; int* y=malloc(sizeof(int)); *y = 4; int z = fun(x, y); printf("%d", z);}
Or like this:
main(){ int x=3,y=4; int z = fun(&x, &y); printf("%d", z);}