From e28f0b9c086586ea8bf71a186920217ec5caf3b8 Mon Sep 17 00:00:00 2001 From: tocariimaa Date: Thu, 13 Feb 2025 13:32:57 -0300 Subject: [PATCH] articles/pointer.md: update --- articles/pointer.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/articles/pointer.md b/articles/pointer.md index a3a86cd..97aca4b 100644 --- a/articles/pointer.md +++ b/articles/pointer.md @@ -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