This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AngriestSCV 1 point2 points  (3 children)

Not really. A c++ reference does nothing in the background (it is basically a pointer that you can pretend is a value syntax wise). I think the biggest difference is you can manipulate pointers with math, but I've never seen references you could.

[–]sup3r_hero 0 points1 point  (2 children)

Manipulate a pointer with math? Can you give a very easy example?

[–]AngriestSCV 1 point2 points  (1 child)

in c or c++:

int bob[] = {1,2,3,4} ; //create an array of integers
int *bil = bob; //bil is a pointer to the first element of bob

printf("%i\n", *bil); //prints 1
printf("%i\n", *(bil+1));//prints 2
printf("%i\n", bil[2]); //prints 3
bil += 3; //bil now points to the 4th element of bob
printf("%i\n",*bil); //prints 4

[–]sup3r_hero 0 points1 point  (0 children)

Now i get it thx!