articles/pointer.md: update
This commit is contained in:
parent
fefe7e1ef3
commit
323906de43
1 changed files with 4 additions and 3 deletions
|
@ -6,7 +6,7 @@ Here, the pointer `str` has the value of 0xdecade, therefore pointing to the mem
|
||||||
that address (here a C string):
|
that address (here a C string):
|
||||||
|
|
||||||
address | data
|
address | data
|
||||||
-----------------
|
----------+-------
|
||||||
uint16_t *n ---> 0xdecadb | 0x27
|
uint16_t *n ---> 0xdecadb | 0x27
|
||||||
0xdecadc | 0x7f
|
0xdecadc | 0x7f
|
||||||
0xdecadd | 0xff
|
0xdecadd | 0xff
|
||||||
|
@ -17,6 +17,7 @@ char *str -----> 0xdecade | 'H'
|
||||||
0xdecae2 | 'o'
|
0xdecae2 | 'o'
|
||||||
char *end -----> 0xdecae3 | 0x00
|
char *end -----> 0xdecae3 | 0x00
|
||||||
0xdecae4 | 0x27
|
0xdecae4 | 0x27
|
||||||
|
----------+------
|
||||||
|
|
||||||
char c = *str; /* dereferencing, reading the first element */
|
char c = *str; /* dereferencing, reading the first element */
|
||||||
char c4 = *(str + 4); /* with pointer arithmetic we can access the 4th element, 'o' */
|
char c4 = *(str + 4); /* with pointer arithmetic we can access the 4th element, 'o' */
|
||||||
|
@ -56,5 +57,5 @@ process. On embedded systems (without a MMU), a null pointer may represent a val
|
||||||
|
|
||||||
## Function pointers
|
## Function pointers
|
||||||
Function pointers are more special. On most systems, just like a regular pointer, a function pointer is simply
|
Function pointers are more special. On most systems, just like a regular pointer, a function pointer is simply
|
||||||
a memory address to the start of the function code. Formally in C, dereferencing a function pointer is undefined
|
a memory address to the start of the function code. In some weird architectures like Itanium it is a pair of two addresses.
|
||||||
behavior.
|
Formally in C, dereferencing a function pointer is undefined behavior.
|
||||||
|
|
Loading…
Add table
Reference in a new issue