fork(1) download
  1. #include <stdio.h>
  2.  
  3. #define COUNT_OF_PCHAR 3
  4.  
  5. int main(void) {
  6. char *ptrStore[COUNT_OF_PCHAR] = {0};
  7. char **ptr = &ptrStore[0];
  8. int n, m;
  9. char *temp;
  10. char *string3 = "YOU";
  11. char *string2 = "FOR";
  12. char *string1 = "BOOK";
  13.  
  14. // before store any pointer to it
  15. printf("before:\n");
  16. printf("ptrStore[0] 位址:%p\n", ptrStore[0]);
  17. printf("ptrStore[1] 位址:%p\n", ptrStore[1]);
  18. printf("ptrStore[2] 位址:%p\n", ptrStore[2]);
  19. printf("\n");
  20.  
  21. temp = string1;
  22. *ptr = temp;
  23. *(ptr + 1) = string2;
  24. *(ptr + 2) = string3;
  25.  
  26. // after store pointer to it
  27. printf("after:\n");
  28. printf("ptrStore[0] 位址:%p\n", ptrStore[0]);
  29. printf("ptrStore[1] 位址:%p\n", ptrStore[1]);
  30. printf("ptrStore[2] 位址:%p\n", ptrStore[2]);
  31. printf("\n");
  32.  
  33. printf("\"BOOK\" 位址:%p\n", string3);
  34. printf("\"FOR\" 位址:%p\n", string2);
  35. printf("\"YOU\" 位址:%p\n", string1);
  36. printf("\n");
  37.  
  38. printf("string3 位址:%p\n", &string3);
  39. printf("string2 位址:%p\n", &string2);
  40. printf("string1 位址:%p\n", &string1);
  41. printf("\n");
  42.  
  43. for (n = 0; n < COUNT_OF_PCHAR; n++) {
  44. printf("*(ptr+%d) 所存的位址 %p\n", n, *(ptr + n));
  45. printf("(ptr+%d) 本身的位址 %p\n", n, (ptr + n));
  46. printf("*(ptr+%d) 指向字串 %s\n", n, *(ptr + n));
  47. for (m = 0; *(*(ptr + n) + m) != '\0'; m++) {
  48. printf("*(*(ptr+%d)+%d) = %c \n", n, m, *(*(ptr + n) + m));
  49. }
  50.  
  51. }
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
before:
ptrStore[0] 位址:(nil)
ptrStore[1] 位址:(nil)
ptrStore[2] 位址:(nil)

after:
ptrStore[0] 位址:0x8048758
ptrStore[1] 位址:0x8048754
ptrStore[2] 位址:0x8048750

"BOOK" 位址:0x8048750
"FOR" 位址:0x8048754
"YOU" 位址:0x8048758

string3 位址:0xbfb58d08
string2 位址:0xbfb58d0c
string1 位址:0xbfb58d10

*(ptr+0) 所存的位址 0x8048758
(ptr+0) 本身的位址 0xbfb58d14
*(ptr+0) 指向字串 BOOK
*(*(ptr+0)+0) = B 
*(*(ptr+0)+1) = O 
*(*(ptr+0)+2) = O 
*(*(ptr+0)+3) = K 
*(ptr+1) 所存的位址 0x8048754
(ptr+1) 本身的位址 0xbfb58d18
*(ptr+1) 指向字串 FOR
*(*(ptr+1)+0) = F 
*(*(ptr+1)+1) = O 
*(*(ptr+1)+2) = R 
*(ptr+2) 所存的位址 0x8048750
(ptr+2) 本身的位址 0xbfb58d1c
*(ptr+2) 指向字串 YOU
*(*(ptr+2)+0) = Y 
*(*(ptr+2)+1) = O 
*(*(ptr+2)+2) = U