5 ms·
> A pointer is an integer that indicates a position in RAM, ROM, NVRAM, flash, etc. A pointer stores a number that represents an address, without making refer
by scoutt 6y ago
> A pointer is an integer that indicates a position in
RAM, ROM, NVRAM, flash, etc.
A pointer stores a number that represents an address, without making reference where is located. Can be 0 (NULL).
"p+1" can be the next byte in RAM, or the next 4KB if p is of type "4KB struct".
- blondin 6y agoyes, i find OP's definition very clear and by saying number instead of integer you made it even better. for example i was re-reading some math stuff yesterday that made me realize that sometimes we want natural number instead of integer which can be negative...
- SAI_Peregrinus 6y agoNULL doesn't strictly have to be 0. It usually is, but it could be defined differently depending on the architecture.
- enriquto 6y ago> A pointer stores a number Why not "is" instead of "stores" ?
- scoutt 6y agoA variable that is a pointer occupies space in memory. In that memory (the pointer of the pointer) is stored the number. char* ptr = (char*) 0x80000000; By doing `&ptr` you can know the address of the pointer `ptr`. In that address, the number 0x80000000 is stored.
- enriquto 6y agoI sort of disagree... The pointer can be stored in a register and it does not take memory.
- Twisol 6y agoRegisters are simply the fastest, closest kind of memory for a CPU to use. They're still memory, in that you can put something there and remember it for later.
- scoutt 6y agopointer != address Unless there is no difference between a pointer and an address, in a register you can store an address, maybe the address of a pointer (and so on). But you can be right if we talk about some registers that always point to something, like IP (PC). But we enter into a philosophic area. Edit: Yes, I know, you can also treat a register as a pointer. Should we leave it to the Wikipedia definition? https://en.wikipedia.org/wiki/Pointer_(computer_programming) https://en.wikipedia.org/wiki/Pointer_(computer_programming)
- msla 6y ago> A pointer stores a number I disagree with this, and I think it's important to understanding pointers. A pointer is a number. A variable stores a value.[1] A variable has an address, a value does not; a value might be stored at an address, but it doesn't intrinsically have an address. A person might live in a building, but the building has the address, not the person, who can move. [1] (In C-like languages this is true. In Python, a variable stores something you're largely not allowed to inspect, which might be a pointer to a data structure with data and metadata. Haskell has no variables, just names for constants.)
- scoutt 6y agoIf I put you in front of a wall full of numbers, and I tell you "point a number with your finger and remember it", what is your finger? A number? Or the thing you use to point a number?