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.