Codementor Events

C - Pointer - Simple but Interesting

Published Nov 09, 2020
C - Pointer - Simple but Interesting

There are some young programmers that have had excellent understanding about the modern languages but rather confused about the pointers.

Sometime, we see char*, char&, const char&, const char* or const char*&...
Those are related to the pointers, references...

So, what are they?

The above image shows the variable (pch) is on the stack memory, the real data is on the heap memory.

The pch variable is the pointer.

What does it store? It stores the memory address of the heap memory. That means it stores 0x83FF2300. We can say that it stores the first memory address of the array.,

How about the 0x83FF2300, 0x83FF2301, 0x83FF2302? In C language, we cannot know the length of the array. That's why we should define one more variable to store the length of the array such as int length = 2.

If the statement is;

*pch = 'a';

that means 'a' is stored at the address: 0x83FF2300.
In the ASCII table, 'a' is 0x61
(https://www.genuinecoder.com/wp-content/uploads/2012/07/asciifull.gif)

Discover and read more posts from Thanh Do Cong
get started
post commentsBe the first to share your opinion
Show more replies