fork(11) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void showArray(int arr[], int n)
  6. {
  7. for(int i = 0; i < n; i++) cout << arr[i] << " ";
  8. cout << endl;
  9. }
  10. void someFunction(int x[], int n) // changes the original values
  11. {
  12. x[0] = 2;
  13. x[1] = 1;
  14. x[2] = 0;
  15. }
  16. void someFunction2(int * x, int n)
  17. {
  18. x[0] = 2;
  19. x[1] = 1;
  20. x[2] = 0;
  21. } // changes the original values
  22. int someFunction3(int x[], int n)
  23. {
  24. x[0] = 2;
  25. x[1] = 1;
  26. x[2] = 0;
  27. return 0;
  28. } // changes the original values
  29. int someFunction4(int x[], int n)
  30. {
  31. x = new int[n];
  32. std::cout << x << endl;
  33. x[0] = 2;
  34. x[1] = 1;
  35. x[2] = 0;
  36. return 0;
  37. } // does NOT change the original value
  38.  
  39. int main(void)
  40. {
  41. int * y = new int[3];
  42. y[0] = 0;
  43. y[1] = 1;
  44. y[2] = 2;
  45. showArray(y, 3);
  46.  
  47. std::cout << y << endl;
  48.  
  49. someFunction4(y, 3) ;
  50. std::cout << y << endl;
  51.  
  52. showArray(y, 3);
  53. return 0;
  54. }
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
0 1 2 
0x943b008
0x943b018
0x943b008
0 1 2