c++ - Functionality of pointers and references -


i'm pretty beginner @ c++. started learning few weeks ago. i'm interested in improving skills programmer, , there's that's been confusing me in last few days. pointers. pointers , reference operator. question is, functionality of pointers , reference operator? how know when use them, , purposes , common usages. examples consisting of common algorithms using dereference , reference appreciated.

how can use reference , dereference become better programmer, , improve algorithms(and possibly make them simpler)?

thanks :d

definitely check this question out, accepted answer explains pointers , common errors them in nice manner.

update: few words of own

pointers bunches of bits, other kind of variable. use them because have several convenient properties:

  • their size (in bytes) fixed, making trivial know how many bytes need read value of pointer.

when using other types of variables (e.g. objects), mechanism needs in place compiler knows how large each object is. introduces various restrictions vary among languages , compilers. pointers have no such problems.

  • their size small (typically 4 or 8 bytes), making fast update values.

this useful when use pointer token points potentially large amount of information. consider example: have book pictures of paintings. need describe painting me, can find in book. can either sit down , paint exact copy of it, show me, , let me search book it; or can tell me "it's in page 25". using pointer, , faster.

  • they can used implement polymorphism, 1 of foundations of object-oriented-programming.

so, find out how use pointers: find cases these properties come in handy. :)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -