articles/pointer.md: update
This commit is contained in:
parent
287d2d5557
commit
e28f0b9c08
1 changed files with 6 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
# Pointer
|
||||
In a very simple sense, a pointer represents the memory address of a certain block of data (also can be a single byte) in memory.
|
||||
In a very simple sense, a pointer represents the memory address of a certain datum of a certain size in memory.
|
||||
|
||||
```
|
||||
Here, the pointer `str` has the value of 0xdecade, therefore pointing to the memory at
|
||||
|
@ -27,7 +27,7 @@ char c4 = str[4]; /* array indexing is syntax sugar for *(arr + index) in C
|
|||
str[0] = 'h'; /* equivalent in C */
|
||||
```
|
||||
|
||||
In C (and almost all languages that have pointers), a pointer is an integer type, big enough to hold the entire valid
|
||||
In [C](c.md) (and almost all languages that have pointers), a pointer is an integer type, big enough to hold the entire valid
|
||||
address space of the host system.
|
||||
|
||||
```c
|
||||
|
@ -50,10 +50,12 @@ while (s < send) {
|
|||
```
|
||||
|
||||
## Null pointer
|
||||
A null pointer is a special case, which points to an invalid memory address (nowadays almost 0).
|
||||
A null pointer is a special case, which points to an invalid memory address (nowadays almost always 0).
|
||||
Usually a null pointer is meaningful only in hosted environments, in that case reading or writing from
|
||||
a null pointer will case a segmentation fault error, in which the OS will immediately kill the offending
|
||||
process. On embedded systems (without a MMU), a null pointer may represent a valid memory address.
|
||||
process. On embedded systems (without a MMU), a null pointer may represent a valid memory address. On C
|
||||
the expression `(void *)0` is guaranteed to always produce a null pointer, even if the actual null pointer
|
||||
address is not zero.
|
||||
|
||||
## Function pointers
|
||||
Function pointers are more special. On most systems, just like a regular pointer, a function pointer is simply
|
||||
|
|
Loading…
Add table
Reference in a new issue