23.03.2013 Views

Arrays, parameter passing, pointers and dynamic allocation. - ELIS

Arrays, parameter passing, pointers and dynamic allocation. - ELIS

Arrays, parameter passing, pointers and dynamic allocation. - ELIS

SHOW MORE
SHOW LESS

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 = &num; 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

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!