Subscribe For Free Updates!

We'll not spam mate! We promise.

Apr 14, 2013

How do I use references?



How do I use references?

A reference is merely an initialized pointer. This reduces signi cantly zero pointer and
un-initialized pointers errors. Prefer references to pointers. Although the two following
codes look equivalent, the second implementation prevents invalid compilation.

// in C // in C++

int i; int i;
int *pi = &i; int &ti = i;
int *pj; int &rj; // g++ refuses to compile that
*pi = 0; ri = 0;
*pj = 0; // segfault rj = 0;

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment