How to Approach Pointers in C? [duplicate]

2020-07-09 10:22发布

I am very new to C and I have some problems learning about pointers. I experimented swapping and that's all what I can do with them :) I know that every variable has its own address in memory cells (this is what my lecturer told us) and every variable's value can be obtained by going to its associated address and then fetching the value stored in it. I've seen some function headers such as:

int doSomething(char **hihi);

my head is so confused. I know that pointer is a variable too and it only stores address information in its memory cell. I read that they are closely related to arrays

arr = &arr[0];

That's all what I know about pointers and I wonder how I can deepen my vision upon pointers. I searched the net and I could not find any useful cheatsheet covering pointers. And I also want to know why they are so important and is there any way to understand actually what is going on without using printf() to print their addresses(p) and values(\*p)??

标签: c pointers
13条回答
再贱就再见
2楼-- · 2020-07-09 10:58

Many good answers given above. Some other insight is that a pointer is always an unsigned integer type. The object or variable it points to in memory may be of any type.

In a 32-bit operating system the integer is a 4-byte number and must be in the range

0 < pointer value < (2^^32) -1

In a 64-bit operating system the integer is an 8-byte number and must be in the range

0 < pointer value < (2^^64) -1

A pointer value = 0 is interpreted as a special flag value called NULL, which indicates this pointer does not point to a usable variable.

Pointers are used for indirection. Some registers in a CPU act as pointers, e.g. the program counter (PC) and address registers.

查看更多
登录 后发表回答