First, the pointer variable
1. Variables for storing addresses
2. * Indirect address character
3.%p The format character of the print address
4. & Take address character to get the storage unit address of the variable
5, int *p = &a p points to a storage unit [p is a variable where the pointer stores the address]
6. *p storage unit (content) for accessing variables via address
Second, the pointer
int a[5]={3,4,1,2,5}; int *p = A; // define a pointer to the first address printf ("p[2] =%d\n", p[1]); printf ("%d\n", * (p+1));
Three, a string pointer
CharStr[] ="Hello"; Char* PS =str; intCount =0;//int n = 0; for(inti =0; Str[i]! =' /'; i++) {//* (ps+n)! = ' + ';printf"%c", *ps);//n++;ps++; Count++; } printf ("%d", count);
Iv. exchange of two variables
voidSwapint*a,int*b) { inttemp = *A; *a = *b; *b =temp; printf ("%d%d", *a,*b);} intMainintargcConst Char*argv[]) { intA =1; intb =2; Swap (&a,&b);return 0;}
Five, array sorting
voidAddint*arr,intLen) { for(inti =0; I < len-1; i++) { for(intj =0; J < Len-1-I.; J + +) { if(* (ARR+J) > * (arr+j+1)) { inttemp = * (arr+j); * (ARR+J) = * (arr+j+1); * (arr+j+1) =temp; } } } for(inti =0; i < Len; i++) {printf ("%d", * (arr+i)); }}intMainintargcConst Char*argv[]) { intArr[] = { -, the, at, About,Panax Notoginseng}; Add (arr,5); return 0; }
1, array sort 2
voidAddint* p,intLen) { for(inti =0; i<len-1; i++) { for(intj =0; J < len-1-I.; J + +) { if(* (P+J) >* (p+j+1)) { inttemp; Temp= * (p+j); * (P+J) = * (p+j+1); * (p+j+1) =temp; } } } for(inti =0; i < Len; i++) {printf ("%d", * (p+i)); }}intMainintargcConst Char*argv[]) { intArr[] = { -, the, at, About,Panax Notoginseng}; int* p =arr;//defines the pointer to the first address of Add (p,5); return 0; }
C Language Basics _ Pointers