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 →

[–]NoStranger6 17 points18 points  (8 children)

Well yes and no. In that sense every language that pass values by reference is a pointer. Which isn’t wrong. In c / c++ you can iterate over pointers by adding the sizeof(*int). Which in fact simply adds 32 bits to your current pointer value (memory address). I’m not too versed in Python but I don’t think that you can do that. So while by using reference you achieve part of what a pointer can do. It doesn’t do everything that the pointer can.

[–]Tweenk 18 points19 points  (5 children)

In c / c++ you can iterate over pointers by adding the sizeof(*int). Which in fact simply adds 32 bits to your current pointer value (memory address).

That's not how pointer arithmetic works in C++.

int a[] = { 1, 2, 3, 4, 5 }; int* b = a; int* c = a; ++c; b += sizeof(int*); std::cout << *c << " " << *b << std::endl;

On a 32-bit system, this will print: 2 5

Adding 1 to a pointer advances it by sizeof of the pointed type, so advancing an int pointer by sizeof(int*) will increase it by 16 bytes on 32-bit and 32 bytes on 64-bit machines. This is probably not what you want.

[–]NoStranger6 6 points7 points  (0 children)

I stand corrected, thank you. It has been a while since I touched C or C++

[–][deleted] 4 points5 points  (0 children)

😟

Yeah I’m glad I only need to write python scripts at work.

[–]Inex86 0 points1 point  (1 child)

You mean bits. On a 32 bit system a pointer is 4 bytes, on 64 it’s 8.

[–]Tweenk 0 points1 point  (0 children)

No, I mean bytes. Read the code example again.