Lesson 19 of 23
Call by Reference: SwapCall by Reference: Swap
9 min 35 XP
Function-க்கு variable-ன் address-ஐ அனுப்பினால், function அந்த variable-ஐயே மாற்ற முடியும். scanf(&x) இப்படித்தான் வேலை செய்கிறது. பல மதிப்புகளைத் திருப்பித் தரவும் இதுவே வழி.
Pass a variable's address and the function can change the variable itself. That's exactly how scanf(&x) works, and it is also how a function returns more than one value.
Example: edit me and press Run
Press Run to see the result here.Array-ஐ function-க்கு அனுப்பும்போது அதன் முதல் உறுப்பின் address தான் போகிறது. ஆகவே function array-ஐ மாற்றினால் main-லும் மாறும்.
Passing an array to a function passes the address of its first element, so changes made in the function are visible in main too.