Example 1: Enter a and b two integers, output the values of a and B in order of magnitude.
1#include <stdio.h>2 intMain ()3 {4 int*p1,*p2,*p,a,b;5printf"Please enter a total of two integers:");6scanf"%d,%d", &a,&b);//when entering a number, be sure to use the comma in the English state.7 p1=&a;8 p2=&b;9 if(a<b)Ten { Onep=P1; Ap1=P2; -P2=p; - } theprintf"a=%d,b=%d\n", A, b); -printf"max=%d,min=%d\n", *p1,*p2); - return 0; -}
The example 2:swap () function implements the value of exchanging two variables.
1 intMain ()2 {3 void swap (int *p1,int *p2);4 intb;5 int *pointer_1,*pointer_2;6printf"Please enter a and B:");7scanf"%d,%d",&a,&b);8 pointer_1=&a;9 pointer_2=&b;Ten swap (pointer_1,pointer_2); //swap (A, B) is wrong Oneprintf"a=%d,b=%d\n", A, b); A return 0; - } - voidSwapint*P1,int*p2) the { - inttemp; -temp=*P1; -*p1=*P2; +*p2=temp; -}
To be continued, do not look at the C, review Java, tomorrow after the test to see the pointer part.
C Language Pointer Instance practice