fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. void display(char *s)
  5. {
  6. std::cout << "Display" << std::endl;
  7. }
  8.  
  9. void display(const char *s)
  10. {
  11. std::cout << "Display with const" << std::endl;
  12. }
  13.  
  14. int main()
  15. {
  16. char *str = strdup("boap");
  17. const char *str2 = "toto";
  18. /* It is a string literral "bound" as a char *.
  19.   Compiler will issue warning, but it still compiles.
  20.   Avoid to do that, it's just an exemple */
  21. char *not_safe = "not_safe";
  22.  
  23. display("llama");
  24. display(str2);
  25. display(str);
  26. display(not_safe);
  27. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
Display with const
Display with const
Display
Display