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~
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~
You can get cleaner syntax with references, but they can't be re-assigned to 'point' elsewhere and must be initialised immeadiately.
zen
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
and references cannot be NULL.