Lesson 19 of 23

Call by Reference: Swap

9 min 35 XP

Function-க்கு variable-ன் address-ஐ அனுப்பினால், function அந்த variable-ஐயே மாற்ற முடியும். scanf(&x) இப்படித்தான் வேலை செய்கிறது. பல மதிப்புகளைத் திருப்பித் தரவும் இதுவே வழி.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

Array-ஐ function-க்கு அனுப்பும்போது அதன் முதல் உறுப்பின் address தான் போகிறது. ஆகவே function array-ஐ மாற்றினால் main-லும் மாறும்.

Challenge

+35 XP

void divide(int a, int b, int *q, int *r) என்ற function எழுதுங்கள்: q-ல் ஈவு, r-ல் மீதி. main()-ல் a, b படித்து print செய்யுங்கள். Input: 17 5 Output: Quotient 3, Remainder 2

Output Loading C (first time takes a few seconds)
Press Run to see the result here.