Guest User

Untitled

a guest
Apr 26th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. void chchar(char* ch){
  2. ch = "asfafgag";
  3. }
  4.  
  5. char* array = "abc";
  6. chchar(array);
  7. cout << array;
  8.  
  9. #include <iostream>
  10. #include <cstring>
  11. #include <stdlib.h>
  12. using namespace std;
  13.  
  14. void chchar(char** str)
  15. {
  16. strcpy(*str, "String data from `chchar`");
  17. }
  18.  
  19. int main(int argc, char** argv)
  20. {
  21. char* data = static_cast<char*>(malloc(sizeof(100)));
  22. strcpy(data, "Blablbla");
  23. printf("Data before call `chchar`: %sn", data);
  24. chchar(&data);
  25. printf("Data before call `chchar`: %sn", data);
  26. free(data);
  27. system("pause");
  28. }
  29.  
  30. #include <iostream>
  31. #include <cstring>
  32. #include <stdlib.h>
  33. using namespace std;
  34.  
  35. void chchar(char*& str)
  36. {
  37. strcpy(str, "String data from `chchar`");
  38. }
  39.  
  40. int main(int argc, char** argv)
  41. {
  42. char* data = static_cast<char*>(malloc(sizeof(100)));
  43. strcpy(data, "Blablbla");
  44. printf("Data before call `chchar`: %sn", data);
  45. chchar(data);
  46. printf("Data before call `chchar`: %sn", data);
  47. free(data);
  48. system("pause");
  49. }
Add Comment
Please, Sign In to add comment