Loading [MathJax]/jax/output/HTML-CSS/config.js

搜尋此網誌

[C/C++][傳遞與回傳字串]

  1. /*
  2. * Author: MH
  3. * Since 2013/10/21
  4. * Toolkit: Code::Block 12.11
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. void returnString(char **str2)
  10. {
  11. printf("before: %s\n", *str2); // before: abc
  12. *str2 = "def";
  13. printf("after: %s\n", *str2); // before: def
  14. }
  15.  
  16. int main()
  17. {
  18. char *str1 = "abc";
  19.  
  20. printf("before returnString: %s\n", str1); // before returnString: abc
  21. returnString(&str1);
  22. printf("after returnString: %s\n", str1); // before returnString: def
  23.  
  24. return 0;
  25. }

沒有留言:

張貼留言