#include <stdio.h> int main () { int A [ . 5 ] = { . 1 , 2 , . 3 , 4 , . 5 }; int * p = & A [ . 3 ]; // where p points to the array element of the fourth 4 the starting address. p = * 100 ; the printf ( " % D \ n- " , * p ++ ); // take the first value p at 100 , and then to increment the pointer p. 1; the printf ( " % D \ n- " , the P-- * ); //
the printf ( " % D \ n- " , * - p); // first pointer p 1 is decremented, and then take the value pointed to return 0; } // 100 5 3
* P ++, (* p) ++, * difference ++ p, ++ * p of
int a[5]={1,2,3,4,5};
p = A * int;
* p ++ to take the value of the pointer p points ( the first element of the array 1), and then increment the pointer p 1 ;
COUT << * p ++; // result is 1
COUT << (* p ++); 1 //
(* p) ++ p points go pointer value (a first element of the array), then the value is incremented by one (becomes the first element of the array 2
COUT << (* p) ++ ; // 1
COUT << ((* p) ++) // 2
* p ++ first pointer p is incremented by one (in this case points to the second element of the array), * and then taken out of the operation value
cout << * p ++; // 2
COUT << (* p ++) // 2
++ * p to take the value of the pointer p points (the first array element 1), then the value is incremented by one (the first array element becomes 2)
cout << * P ++; 2 //
cout << (* P ++) // 2
Note that the above cout each output to a separate output to get the results back.
string pointer
#include <stdio.h> int main() { char buffer[10]="ABC"; char *pc; pc="hello"; printf("%s\n",pc); pc++; printf("%s\n",pc); printf("%c\n",*pc); pc=buffer; printf("%s\n",pc); return 0; }
#include <stdio.h> int main() { int a[4]={1,3,5,7}; printf("%p\n",a); printf("%p\n",a+1); printf("%p\n",&a); printf("%p\n",&a+1); printf("%p\n",*(&a)); printf("%p\n",*(&a)+1); return 0; }
p = A * int;
* p ++ to take the value of the pointer p points ( the first element of the array 1), and then increment the pointer p 1 ;
COUT << * p ++; // result is 1
COUT << (* p ++); 1 //
(* p) ++ p points go pointer value (a first element of the array), then the value is incremented by one (becomes the first element of the array 2
COUT << (* p) ++ ; // 1
COUT << ((* p) ++) // 2
* p ++ first pointer p is incremented by one (in this case points to the second element of the array), * and then taken out of the operation value
cout << * p ++; // 2
COUT << (* p ++) // 2
++ * p to take the value of the pointer p points (the first array element 1), then the value is incremented by one (the first array element becomes 2)
cout << * P ++; 2 //
cout << (* P ++) // 2
Note that the above cout each output to a separate output to get the results back.
string pointer
#include <stdio.h> int main() { char buffer[10]="ABC"; char *pc; pc="hello"; printf("%s\n",pc); pc++; printf("%s\n",pc); printf("%c\n",*pc); pc=buffer; printf("%s\n",pc); return 0; }
#include <stdio.h> int main() { int a[4]={1,3,5,7}; printf("%p\n",a); printf("%p\n",a+1); printf("%p\n",&a); printf("%p\n",&a+1); printf("%p\n",*(&a)); printf("%p\n",*(&a)+1); return 0; }