🔵 Core C++  ·  Lesson 25

References in C++

References in C++

What is References in C++?

References in C++
A reference is an alias for another variable. References are commonly used to pass values to functions without copying and to modify original variables.
Level
🔵 Core C++ Features
Example File
references.cpp
Main Focus
Concept + syntax + practical C++ program

Why should you learn this?

  • It helps you write correct and readable C++ programs.
  • It is used repeatedly in school practicals, projects and competitive programming.
  • It builds the base for advanced topics such as OOP, STL and data structures.

Important Terms

TermMeaning / Use
referenceReference used in References in C++ programming.
aliasAlias used in References in C++ programming.
pass by referencePass by reference used in References in C++ programming.
& operator& operator used in References in C++ programming.

Syntax / Pattern

int &ref = variable;

Example Program

#include <iostream>
using namespace std;
void increase(int &x){ x += 10; }
int main(){
    int marks = 70;
    increase(marks);
    cout << marks;
    return 0;
}

Expected Output

80

Program Explanation

  • x is a reference to marks.
  • Changing x changes original marks.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.

Where will you use it?

  • function parameters
  • large objects
  • operator overloading

Common Mistakes

  • Not initializing a reference.
  • Thinking reference can be reseated like pointer.

Practice Tasks

  1. Swap two numbers using references.
  2. Explain reference vs pointer.

Summary

References in C++ is an important C++ topic. Learn the definition, understand the syntax, run the example program and then solve the practice tasks to make the concept strong.

What is References in C++?

References in C++
A reference is an alias for another variable. References are commonly used to pass values to functions without copying and to modify original variables.
Level
🔵 Core C++ Features
Example File
references.cpp
Main Focus
Concept + syntax + practical C++ program

Why should you learn this?

  • It helps you write correct and readable C++ programs.
  • It is used repeatedly in school practicals, projects and competitive programming.
  • It builds the base for advanced topics such as OOP, STL and data structures.

Important Terms

TermMeaning / Use
referenceReference used in References in C++ programming.
aliasAlias used in References in C++ programming.
pass by referencePass by reference used in References in C++ programming.
& operator& operator used in References in C++ programming.

Syntax / Pattern

int &ref = variable;

Example Program

#include <iostream>
using namespace std;
void increase(int &x){ x += 10; }
int main(){
    int marks = 70;
    increase(marks);
    cout << marks;
    return 0;
}

Expected Output

80

Program Explanation

  • x is a reference to marks.
  • Changing x changes original marks.
Exam Tip: In C++ practical answers, write the logic first, then the program, then expected output. For theory, always include one suitable example.

Where will you use it?

  • function parameters
  • large objects
  • operator overloading

Common Mistakes

  • Not initializing a reference.
  • Thinking reference can be reseated like pointer.

Practice Tasks

  1. Swap two numbers using references.
  2. Explain reference vs pointer.

Summary

References in C++ is an important C++ topic. Learn the definition, understand the syntax, run the example program and then solve the practice tasks to make the concept strong.

← Back to C++ Tutorial