fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. void func(int i, int h, char* tab = new char[3])
  7. {
  8. tab[i] = h;
  9. cout << "tab[i] = " << (int)tab[i] << endl;
  10. delete [] tab;
  11. }
  12.  
  13. void func2(char* t = NULL)
  14. {
  15. bool freeWhenFinished = t == NULL;
  16. if (freeWhenFinished)
  17. {
  18. t = new char[3];
  19. }
  20.  
  21. cin >> t[2];
  22. cout << "t[2] = " << (int)t[2] << endl;
  23.  
  24. if (freeWhenFinished)
  25. {
  26. delete [] t;
  27. }
  28. }
  29.  
  30. int main()
  31. {
  32. int a, b;
  33. cin >> a >> b;
  34. func(a, b);
  35. func2();
  36. return 0;
  37. }
Success #stdin #stdout 0s 3476KB
stdin
1 2 3
stdout
tab[i] = 2
t[2] = 51