Arrays, parameter passing, pointers and dynamic allocation. - ELIS
Arrays, parameter passing, pointers and dynamic allocation. - ELIS
Arrays, parameter passing, pointers and dynamic allocation. - ELIS
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
S Differences<br />
Pointers vs. References<br />
S In reference declaration (int &cRef = count;), “&” is part of type,<br />
it is not an operation (as with <strong>pointers</strong>)<br />
S References have to be initialized at declaration time<br />
S void func_ptr(int *pi) {*pi = 5;}<br />
S void func_ref(int &ri) {ri = 6;}<br />
S int num; int *p = # int &r = num;<br />
S func_ptr(&num);<br />
S func_ref(num); //We are <strong>passing</strong> <strong>parameter</strong>s by… what?<br />
55