Definition: A pointer is a variable whose value is the address of another variable, and the address represents the location in memory. The thing to remember is that the array variable itself is a pointer.
Type of Address
The address is the type of existence, is not it feels strange, the pointer does not represent an address, the address has a type? See an example:
int *ip; /* A pointer to an integral type */double *DP; /* A double-type pointer */float *FP; /* A floating-point pointer */char *ch; /* A pointer to a character type */
In fact, the pointer is always just a hexadecimal number representing an address, the so-called type, which refers to the type of the variable the pointer is pointing to.
Using pointers
How to define a pointer, the previous example should know, then how to print the hexadecimal address is how much and or what the pointer point to the data is how many:
The address of I was obtained by the & operator and saved to INTP int *intp; = &i;printf ("INTP stores the address:%p, the stored address points to the data:%d\n", INTP, *INTP);
Pointers can be operated: + + 、--、 +,-
In addition, pointers can be compared using relational operators such as = =, < and >
int intarr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};//first defines a pointer to execute the array first element int *INTARRP = &intarr[0];p rintf ("At this time INTARRP storage address is:%p, Data:%d\n ", INTARRP, *INTARRP);//Add a look at the result (each time it is added, it will point to the next integer position) intarrp++;p rintf (" INTARRP storage after the increment:%p, data:%d\n ", INTARRP, *INTARRP);
The pointer can also point to the pointer
int data = 5201314;int *P1 = &data;int **p2 = &p1;printf ("%d\n", data); Are 5201314printf ("%d\n", *p1);p rintf ("%d\n", **P2);
struct and pointer
The use of pointers in the structure is slightly special, mainly because of the particularity of the structure itself, want to use a value in the structure, generally divided into through the structure itself and pointers to the structure of the pointer two cases, see the following example:
struct node{ int val; };/ /first build a struct data struct node Node;node.val = 1;struct node *nodep; Create a pointer to just the struct NODEP = &node;printf ("%d\n", nodep->val);//pointer to struct with->printf ("%d\n", node.val);//structure itself .
Related articles:
A detailed description of the application of ACTIVEMQ in C #
Related videos:
C Language Tutorials