UrbanPro

Learn C++ Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Why c++ introduced reference variable?

Asked by Last Modified  

Follow 0
Answer

Please enter your answer

MS SQL SERVER DBA Trainer

C++ references allow you to create a second name for the a variable that you can use to read or modify the original data stored in that variable.
Comments

C++, C, Embedded, Linux Expert

(A)It makes the syntax more clear and increase the readability of program. E.g: void change(int* a, int* b) (a) // in case of pointer void change (int& a, int& b ) (b) // in case of reference Int main() { int i = 0, int j = 0; change (&i, &j); // in case of pointer change (I, j); //...
read more
(A)It makes the syntax more clear and increase the readability of program. E.g: void change(int* a, int* b) (a) // in case of pointer void change (int& a, int& b ) (b) // in case of reference Int main() { int i = 0, int j = 0; change (&i, &j); // in case of pointer change (I, j); // in case of reference : you can see the difference, it is just like a simple function call } (B) When we use reference, copy can be avoidable which saves the memory. Main difference between pointer and reference are as follows: 1- Pointer can be NULL but reference cannot be. 2- Pointer can hold the address of variables while reference holds the address of duplicate of that variable. 3- Reference must be initializing at the time of declaration but this not the case with pointer. 4- There is no need to dereference the reference but a pointer to be dereferenced. 5- Arithmetic operation cannot be perform on reference whereas can do with pointers. read less
Comments

Expert C/C++ Trainer with over 15 years of Experience

References are alternative of pointers. It is simpler to use references over pointers. Internally references are similar to pointers. Eg: Indirect access using pointers. int x =10; int *ptr = &x; //modify value of x indirectly *ptr = 20; //increment by 1 *ptr++ is wrong (*ptr)++ is correct. Reference int...
read more
References are alternative of pointers. It is simpler to use references over pointers. Internally references are similar to pointers. Eg: Indirect access using pointers. int x =10; int *ptr = &x; //modify value of x indirectly *ptr = 20; //increment by 1 *ptr++ is wrong (*ptr)++ is correct. Reference int &ref=x; ref=20; ref++; Late binding and Run-time polymorphism can be achieved by reference and pointer. I hope u got the basic point. Regard Syed read less
Comments

First we need to understand the difference between the pointers (used in C) and reference variables( used in C++). 1. Pointer is a variable which holds the address of some other variable. 1. In C, pointers were introduced to manipulate the data stored at a particular memory location. 2. It was...
read more
First we need to understand the difference between the pointers (used in C) and reference variables( used in C++). 1. Pointer is a variable which holds the address of some other variable. 1. In C, pointers were introduced to manipulate the data stored at a particular memory location. 2. It was easier to access, store and manipulate the data using pointers e.g. 2d or 3d matrices, or accessing data using pointers in functions, accessing data stored in structures. 3. But pointer could create lot of bugs accidentally (typing mistake like using *(p+1) instead of *(*p+1) or deliberately (to create viruses etc). In C++ and Java, pointers were totally removed to avoid above mentioned issues (bugs, viruses and complexity). 1. Reference variable is another name (alias) given to the same memory location. 2. They work similar to pointers but are easy to use and less complicated. 3. They must be initialized at the time of declaration, unlike pointers in C. (undeclared pointers in C can point anywhere in the memory). 4. In C++ functions, no address operator(&) is used at the time of function call, unlike pointers where (&) operator is used at the time of function call. 5. As 80% of C syntax can be used in C++, pointers can be used in C++ programs also. read less
Comments

C++ references allow you to create a second name for the a variable that you can use to read or modify the original data stored in that variable. While this may not sound appealing at first, what this means is that when you declare a reference and assign it a variable, it will allow you to treat the...
read more
C++ references allow you to create a second name for the a variable that you can use to read or modify the original data stored in that variable. While this may not sound appealing at first, what this means is that when you declare a reference and assign it a variable, it will allow you to treat the reference exactly as though it were the original variable for the purpose of accessing and modifying the value of the original variable--even if the second name (the reference) is located within a different scope. This means, for instance, that if you make your function arguments references, and you will effectively have a way to change the original data passed into the function. This is quite different from how C++ normally works, where you have arguments to a function copied into new variables. It also allows you to dramatically reduce the amount of copying that takes place behind the scenes, both with functions and in other areas of C++, like catch clauses. read less
Comments

Programming in C, C++, Unix

It gives a java style of easier coding, whrein, data can be passed by reference without using complexity of pointer. But so many features still mandate the use of pointers in real life, like *this.
Comments

They allow passing of parameters used for output with no explicit address-taking by the caller. There is no dereferncing implies no confusion
Comments

C,C++17,Data Structure, Algorithm, STL,Multithreading,Async, Assignments - Online tutor

using reference, copy can be avoidable which saves the memory.
Comments

C,C++17,Data Structure, Algorithm, STL,Multithreading,Async, Assignments - Online tutor

While you are passing a big object to a function, it creates a new copy of the same object. So instead of creating a new copy we are just referring the same object. here you will get the benift of using reference.
Comments

Trainer - C# .Net, C++, SQL Server

Depending on the requirement, If user want to change the value of a variable without creating another variable, one can use reference variable.
Comments

View 12 more Answers

Related Questions

Is C/C++ language is still important in 2019?
Of course, C language is only the heart of any processor or controller.Because of complexity in C peoples are looking to work on High-level languages like JAVA etc.
Tejas
0 0
7
Describe about private access specifier?
Private keyword, means that no one can access the class members declared private outside that class. By default class variables and member functions are private.
Prasad
1 1
8
What is the use of virtual keyword in inheritance?
use of virtual keyword in inheritance-------> Multiple inheritance in C++ is a powerful, but tricky tool, that often leads to problems if not used carefully. This article will teach you how to use virtual...
Shabbir
What are the toughest topics in C language?
1. pointer 2. dynamic memory allocation 3. File handling
Lokayya
0 0
5
What is difference between object oriented procedure and object oriented programming?
i.basic building block for procedure orientation is functions while for OOPS its objects.. ii.pop follows top-down hierarchy while opps its just opposite. iii.pop lacks encapsualtion and has acesses...
Madhuranjan

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Programing Languages Learning Tricks
You want to learn that new language or library or framework as soon as possible, right? That’s understandable. Fortunately, there are a handful of tips that can help you to better retain all of that...
H

Harshal G.

0 0
0

Advantages of C++ Language
Advantages of C++ - C++ is a profoundly convenient dialect and is frequently the dialect of decision for multi-gadget, multi-stage application advancement. - C++ is a protest situated programming dialect...

What Would Be Life Cycle Of A Fresher After Campus In An IT Company?
1. Basic Technical Training: Since freshers are not subject matter experts so gone through 3 - 6 months basic technical training within Organization. 2. Technical Assessment: HR sends freshers to various...

Efficient Learning Strategies
Type your notes after class Write your notes onto flashcards - Scrabble -Make posters Review flashcards while walking, at gym, etc. Dog-ear pages in the reading where you can find...

Necessity of Theory and Practical in Computer Science.
Upon studying a subject both theory and practical are important. Usually many schools concentrate more on theory and the marks not on the practical. Other and opposite kind of people prefer practical...

Recommended Articles

Introduction C++ is an excellent programming language and many of the applications are written in C++ language. It has generic, object-oriented & imperative programming features, and also provides facilities for low-level memory manipulation. Successor of C language, it is an OOP (object oriented programming) language...

Read full article >

Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...

Read full article >

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

Read full article >

Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today.  In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...

Read full article >

Looking for C++ Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C++ Language Classes?

The best tutors for C++ Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C++ Language with the Best Tutors

The best Tutors for C++ Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more