About pointers in c language in some of the experiments

We learnpointerWhen there may be a lot of things so that we confuse so I use a few small experimental program to give you answers to your questions:

First, from the definition, the variable is a pointer to the address stored in the variable。

Unary operator * is the indirection or dereference operator

Unary operator&Take for an object address,It can only be applied to objects in memory

That * (indirection get is a specific value stored in memory)

For pointers experiment

Experiment one

The results compiled to


A pointer is a variable that holds the address of the variable,In Experiment 1,


ip address pointing to x to x ip

We will address assigned to the variable x ip

I'm just learning this time in this place is not very deep understanding so there is a test

From the experiments, we can know the difference between a direct addressing and indirect addressing of,I, respectively, in decimal and binary print direct addressing and indirect addressing values,

Direct addressing is printed x address information in memory,Data obtained is directly addressing an address

The indirect addressing is set up on the basis of the direct addressing,Objects Introduction Addressing a value corresponding to the address stored in。

Experiment two



The second experiment we can get the following information

First pointer is a variable,Can be changed。

This tells us a few lines of code to change the assignment of indirect addressing is the address of an object。Before and after the two directly addressed&x The output can be learned


Third experiment

The compiled results

Indirect addressing is the value obtained,Their operation is the value of the arithmetic /


Experiment 4

Results after running

In asc code 123 is represented by the symbol”{

This experiment is very simple to tell us the direct and indirect references cited various relationships,Is a direct reference to the value of the address stored reference value (coding addresses) in asc code 123 is represented by the symbol{Therefore, the output * ip direct reference number 123 the storage location when the represents the symbol”{“.


ps:In 32-bit systems can use int value pointer value can be expressed even unary mutual,Especially referring asc code

Original article written by Gerber drop-off:R0uter's Blog » About pointers in c language in some of the experiments

Reproduced Please keep the source and description link:https://www.logcg.com/archives/286.html

About the Author

Leave a Reply

Your email address will not be published. Required fields are marked *