fork download
  1. //@Author Damien Bell
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6. //Simple function prototype
  7. //int doMath(int, int); //Returns something (int in this case) or nothing (a void)
  8.  
  9.  
  10. //Fill array function to show how to pass an array to -- Prototype
  11. void fillArray(int arrayXYZ[]);
  12.  
  13. int main(){
  14.  
  15. //Case -- switch
  16. //functions
  17. //arrays
  18.  
  19. //int x, y;
  20.  
  21.  
  22. //Simple function
  23. // cout <<" Enter first number ";
  24. // cin >> x;
  25.  
  26. // cout <<" Enter second number ";
  27. // cin >> y;
  28.  
  29. // int sum = (doMath(x,y));
  30.  
  31.  
  32. // cout << "\n" << sum;
  33.  
  34.  
  35.  
  36.  
  37. //Array fill using a function to show pass by reference on arrays
  38.  
  39. int arrayOfInts[5]={0};// 0,1,2,3,4 subscript [5] -- Out of bounds error --returns junk values in c++
  40.  
  41. fillArray(arrayOfInts);//Pass arrayOfInts array into fillArray function.
  42.  
  43. for (int i=0; i<5; i++){//output array loop.
  44. cout << arrayOfInts[i]<<endl;
  45. }
  46.  
  47.  
  48. return 0;
  49. }
  50.  
  51.  
  52. //Simple sum function
  53. //int doMath(int firstNumber, int secondNumber){
  54. // return firstNumber+secondNumber;
  55. //}
  56.  
  57.  
  58.  
  59. //Fill Array function
  60. void fillArray(int arrayXYZ[]){
  61. for (int i=0; i<5; i++){//Propagate array loop
  62. arrayXYZ[i] = i;
  63. }
  64. }
Success #stdin #stdout 0s 2724KB
stdin
Standard input is empty
stdout
0
1
2
3
4