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.