Lesson 8 of 24

References, Pass by Reference

9 min 30 XP

Reference (int& r = x) ഒരു variable-ന്റെ മറ്റൊരു പേരാണ്. Parameter reference ആക്കിയാൽ function-ന് pointers ഇല്ലാതെ caller-ന്റെ variable മാറ്റാം. വലിയ objects copy ചെയ്യാതെ അയയ്ക്കാൻ const& ഉപയോഗിക്കൂ.

Example: edit me and press Run

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

Pointer vs reference: reference null ആകില്ല, മറ്റൊരു variable-ലേക്ക് തിരിച്ചുവിടാനുമാകില്ല. ജനപ്രിയ interview ചോദ്യം.

Challenge

+30 XP

മൂന്ന് values ആരോഹണ ക്രമത്തിലാക്കുന്ന void sortThree(int& a, int& b, int& c) എഴുതൂ. main()-ൽ മൂന്ന് സംഖ്യകൾ വായിച്ച് അത് call ചെയ്ത് print ചെയ്യൂ. Input: 9 2 5 → Output: 2 5 9

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