+ 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; }
4 ответов
+ 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.
+ 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....
+ 3
shortly:
you don’t change variable itself, just using its value in other functions
+ 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.