The output is 11 and idk why. Why is the output 11? Thank u in advance 🙇 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

The output is 11 and idk why. Why is the output 11? Thank u in advance 🙇

void change(int a){ int a=15; a+=x; } int main(){ int a=11; change(a++); change(--a); printf("%i",a); return 0; }

3rd Nov 2018, 3:37 PM
Upar24
Upar24 - avatar
4 Answers
+ 7
call by value......call by reference.... differences In call by value, a copy of actual arguments is passed to formal arguments of the called function and any change made to the formal arguments in the called function have no effect on the values of actual arguments in the calling function. In call by reference, the location (address) of actual arguments is passed to formal arguments of the called function. This means by accessing the addresses of actual arguments we can alter them within from the called function. In call by value, actual arguments will remain safe, they cannot be modified accidentally. In call by reference, alteration to actual arguments is possible within from called function; therefore the code must handle arguments carefully else you get unexpected results.
3rd Nov 2018, 7:19 PM
Peter Stark
+ 4
You should pass int a to the function change by pointer,all you've done is passed int a by value,it wont change a thing if you don't pass it by pointer coz it just creates a copy of the variable... -Check out the C coarse to learn about pointers....
3rd Nov 2018, 3:55 PM
Mensch
Mensch - avatar
+ 3
shortly: you don’t change variable itself, just using its value in other functions
4th Nov 2018, 7:47 PM
Sergei No
Sergei No - avatar
+ 2
In call by value a separate stack is created for a++.Even though the names are same,they will be stored in separate location.The modifications done on a++ value can't effect a value in main.
7th Nov 2018, 4:39 PM
khasimbabu shaik
khasimbabu shaik - avatar