Total members 11893 |It is currently Tue Nov 05, 2024 7:42 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





References confuse me. How do they differ from pointers?
----------------------------------------------------------------------------------

A reference is an alias to a variable, object. They are merely alternate identifiers for the same object. Note that a variable and its reference can be used interchangeably. Hence they are synonyms of each other...Although they contain the address of the object, however they are more like Constant Pointers which cannot be altered.

Regular pointers can be manipulated, i.e. incremented; decremented which can also be dangerous. However a reference cannot be manipulated. Hence they are safer to use because you are not accidentally changing the address of the variable .

cpp code
int actualint;
int& otherint = actaulint;


The real usefulness of references is when they are used to pass values into functions. They provide a way to return values from the function.The reference lets you pass and return large data structures without the overhead of copying them. A reference is also a way to avoid pointer dereferencing syntax in your code. The & operator identifies a reference variable.



_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 109
Have thanks: 5 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : References confuse me. How do they differ from pointers?
 How does JSP differ from Servlets?!!!     -  
 Functions and References     -  
 Constant References     -  
 Basic Pointers     -  
 Swap Using Pointers     -  
 Arrays using Pointers     -  
 Types of Pointers in C++     -  
 How to use pointers and what it means     -  
 The using of pointers between two variables (Swaping)     -  
 pointers to derived types     -  



Topic Tags

C++ Basics






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com