fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. void Show(const char *str, const char **endptr)
  7. {
  8. *endptr = str;
  9. while(**endptr != '\0')
  10. {
  11. printf("address = %p ; value = %c\n",*endptr,**endptr);
  12. ++*endptr;
  13. }
  14. }
  15. int main(int argc, char *argv[])
  16. {
  17. char str[]="ABCDEFG\0";
  18. const char *endptr; // 這裡只能宣告成 const!
  19. printf("address = %p ;\n",endptr);
  20. Show(str,&endptr);
  21. printf("address = %p ;\n",endptr);
  22. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
address = (nil) ;
address = 0xbfbd1ed7 ; value = A
address = 0xbfbd1ed8 ; value = B
address = 0xbfbd1ed9 ; value = C
address = 0xbfbd1eda ; value = D
address = 0xbfbd1edb ; value = E
address = 0xbfbd1edc ; value = F
address = 0xbfbd1edd ; value = G
address = 0xbfbd1ede ;