Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 8:32 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: References confuse me. How do they differ from pointers?
PostPosted: Wed Jul 04, 2007 12:44 am 
Offline
Beginner
User avatar

Joined: Wed Mar 28, 2007 1:17 pm
Posts: 118
Location: Cairo-Egypt
Has thanked: 0 time
Have thanks: 5 time

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.

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.

Thanks alot.


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Arrays using Pointers
 Swap Using Pointers
 Basic Pointers
 Constant References
 A Beginner's Guide to Pointers
 Types of Pointers in C++
 Functions and References
 The using of pointers between two variables (Swaping)
 How does JSP differ from Servlets?!!!

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Google [Bot] and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team