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 विरुद्ध 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.