![]() |
![]() |
![]() |
![]() |
![]() |
|
Whenever a string appears in an expression, the value of that string is a
pointer to the first character in the corresponding character array.
Thus, the following declaration creates a character-pointer variable and arranges
for the initial value of that variable to point to the first character in
the "Food" string:
char *character_pointer = "Food";
Such a character pointer declaration, with a string provided as the initial value, produces the following sort of arrangement in memory:
character_pointer
*--------*--------*
|00000011|10011000| <----- Value of character_pointer variable
*--------*--------* is a pointer to the first element
----------------- of the "Food" string
|
*---*
|
| 0 1 2 3 4 <----- Array index
| | | | | |
v v v v v v
-------- -------- -------- -------- -------- Memory addresses --*
----*--------*--------*--------*--------*--------*--------*--- |
|01000110|01101111|01101111|01100100|00000000| | |
---*--------*--------*--------*--------*--------*--------*---- |
920 921 922 923 924 925 926 <-----*
-------- -------- -------- -------- --------
^ ^ ^ ^ ^
| | | | *----- End-of-string code
F o o d <----- Encoded character