The C instance is a relatively simple instance, but in this instance, it focuses on the more commonly used and error-prone pointer variables in C, including the assignment of pointer variables, the operation of pointer variables, and so on. This example implements a simple implementation by using pointer variables to compare 3 shaping data, making it easy to arrange from small to large, with my code attached below:
#include <stdio.h>/*** Compare the size of three integers with a pointer *@briefMain *@return *//*** pointer, which is the address of the variable, the pointer variable, that is, the variable value = * Pointer to the variable address the type of the cursor variable: * The type description of the pointer variable includes3A content *1: pointer type description, which defines variable as a pointer variable *2: pointer variable name *3: The data type of the variable that the variable value (pointer) points to * Its general form is: * type specifier* ChangeThe volume name;* TableThis is a pointer variable, the variable name is the defined pointer variable name, * The type specifier indicates the data type of the variable that this pointer variable points to * * Pointer variable assignment: * The address operator is provided in C"&"To represent the address of a variable * to give the address of an integer variable A to P can have the following two ways: * (1) pointer variable initialization method *intA *int *p= &a; * (2) Method of assignment statement *intA *int *p* p = &a; * * The meta-calculation of the pointer variable: *1: pointer Operation method * (1) Take address operator & * (2) FETCH content operator * *2: The meta-calculation of the pointer variable * (1) Assignment Operation * (2) Add and Subtract operators*/intMain (void) {int x,y, Z;//Defined3AintTypes of variablesint *xp= &x,/ * Define pointer variable XP and assign the address of X to point to x*/ *yp= &y,/ * Define the pointer variable YP and assign a value of Y to the address so that YP points to y*/ *zp= &z;/ * Defines the pointer variable ZP and assigns the address of Z, which is ZP point to z*/ intTprintf("Please input x,y,z:\n"); scanf" %d%d%d", XP,YP,ZP);/ * Enter a value for the variable through a pointer to the variable * / if(*xp>*yp){/ * Reference the value of a variable by a pointer to a variable * /t =*xp;*xp=*yp;*yp= t; }if(*xp>*zp) {T =*xp;*xp=*zp;*zp= t; }if(*yp>*zp) {T =*yp;*yp=*zp;*zp= t; }printf("x = %d, y = %d, z = %d\ n",x,y, z);return 0;/** * Types related to pointers: * int i;/define integer variable i * int *p;/P is a pointer variable that points to the integer data * int a[n];/define array A, he has n elements * int *p[n];/define pointer array p, he has n pointer elements that point to integer data * INT (*P) [n];/P is a pointer variable * int f () to a one-dimensional array that points to n elements;/F is the function that returns the value of the integer function * int *p ();/P is a function that returns a pointer to the integer data * INT (*p) ();/P is a pointer to a function that returns an integer value of * int **p;/ p is a pointer variable that points to a pointer variable that points to an integral type of data * /}
Using pointers to compare the size of integer data