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

Which are the best books to learn C?
- Yashwant Kanetkar - E Balagurusamy
Kratika
Are C Programmers currently in demand?
Ofcourse, C is alwasy in demand. In the beginning a lot of the big project developed in C language. Now a days, there are a lot of language in market and speciallity is growing in IT field. For a big organization...
Harsha
Which language is best, C, C++, Python or Java?
If you want to learn any languages C#, Java, ect. then must to learn C, C++ language as these are base or language to be strong in language skills. C++ is improved version of C language. C#, Java, J# and etc. which are improved version of C++.
Sribaghya
0 0
6
What are the toughest topics in C language?
1. pointer 2. dynamic memory allocation 3. File handling
Lokayya
0 0
5
Is it possible to write big safe programs in C++?
yes. C++ is generally used to write system software. For example windows operating system are writeen in C++. Most of the operating system, device driver and antivirus programs are written by using C++.
Sapna
0 0
6

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

Ask a Question

Related Lessons

Data Structure: Searching
Searching Searching means finding an element in an array. There are two type of searching techniques : Linear Search Binary Search In linear search, to find the element array is traversed and...

Do You Know Size Of Empty Class and Reason?
Size of empty class is always 1 byte. Reason is, in order to differentiate one object to another object, the size of empty class is always 1 byte. See the below c++ code snippet. Here there are three...

C Programming Language Basics - Easy way to learn
Computer - OverviewTodays world is an information-rich world and it has become a necessity for everyone to know about computers. A computer is an electronic data processing device, which accepts and stores...

File Handling in C++ : Lesson 1 Data Persistence
Data persistence refers to the existence of data in the program. In other words, it means the life of data. Data is the most significant part of a program and it must be stored properly and easily retrieved...
J

Why Indexing Should Start From Zero In Array ?
Why numbering should start at zero? To denote the subsequence of natural numbers 2, 3, ..., 12 without the pernicious three dots, fourconventions are open to usa) 2 ≤ i < 13b) 1 < i ≤ 12c)...

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 >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

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 >

Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...

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