c - Why am I getting this error during run-time? -


i wrote program while watching tutorial compare difference between 'call-by-value' , 'call-by-reference' in c. getting error:

run command: line 1: 1508 segmentation fault: 11 ./"$2" "${@:3}"

help?

main()  { int a,b; scanf("%d %d", &a, &b); printf("before call %d %d", a,b); exch_1(a,b); printf("after first call %d %d", a,b); exch_2(a,b); printf("after second call %d %d \n", a,b);    }  exch_1(i,j) int i, j; {     int temp;     temp = i;     = j;     j = temp; }  exch_2(i,j) int *i, *j; {     int temp;     temp = *i;     *i = *j;     *j = temp; } 

as exch_2 expects addresses parameters, have call exch_2(&a,&b);.

you passing values, , these taken addresses. if e. g. a has value of 5, computer try use value @ address 5on computer - not accessible program.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -