C Board  

Go Back   C Board > General Programming Boards > FAQ Board

 
 
LinkBack Thread Tools Display Modes
Old 10-28-2001, 02:30 PM   #1
Registered User
 
Join Date: Oct 2001
Posts: 11
Pointer & reference

What is the difference between using a pointer and using a reference?
e.g.:

int K;
int*p=&k ;
&ref=k;
(both *p=20; and ref=20; will assign the value 20 into the variable k)

thanks for ur time and help.
~ayesha~
ayesha is offline  
Old 10-28-2001, 04:23 PM   #2
Registered User
 
Join Date: Oct 2001
Posts: 28
The "Cliff Notes" version of your question is a reference is a pointer but with less versatility. The reference is simpler and easier to use. A reference variable cannot be altered to refer to any variable except the one to which it was initialized.
A reference passed to another function is preferred if possible because while the receiving function has a copy of the value in the address passed, it cannot change the value in the original function. Thus protecting the original value.
References cannot be used for array notation.
__________________
rc7j
rc7j is offline  
 

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting an error with OpenGL: collect2: ld returned 1 exit status Lorgon Jortle C++ Programming 6 05-08-2009 08:18 PM
Using Vectors. MinGW warning Viewer C++ Programming 9 03-26-2009 03:15 PM
Undefined Reference Compiling Error AlakaAlaki C++ Programming 1 06-27-2008 11:45 AM
C OpenGL Compiler Error? Matt3000 C Programming 12 07-07-2006 04:42 PM
Pass by pointer, reference, value. Lithorien C++ Programming 8 02-25-2005 10:03 AM


All times are GMT -6. The time now is 01:48 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22