fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void myFunction(string country = "Norway") {
  5. cout << country << "\n";
  6. }
  7.  
  8. //int myFunction(int x, int y) {
  9. // cout << x + y << "\n";
  10. // return x + y;
  11. //}
  12.  
  13. //void swapNums(int& x, int& y) {
  14. // int z = x;
  15. // x = y;
  16. // y = z;
  17. //}
  18.  
  19. //void printArray(int arr[], int size) {
  20. // for (int i = 0; i < size; i++) {
  21. // cout << arr[i] << " ";
  22. // }
  23. // cout << "\n";
  24. //}
  25.  
  26. //int sumFrom1toN(int n) {
  27. // if (n == 1) {
  28. // return 1;
  29. // }
  30. // else {
  31. // return n + sumFrom1toN(n - 1);
  32. // }
  33. //}
  34. int main() {
  35. myFunction("Sweden");
  36. myFunction("India");
  37. myFunction();
  38. myFunction("USA");
  39.  
  40. //myFunction(10, 20);
  41.  
  42. //..................pass by reference..........................//
  43.  
  44. //int firstNum = 10;
  45. //int secondNum = 20;
  46.  
  47. //cout << "Before swap: " << "\n";
  48. //cout << firstNum<< " " << secondNum << "\n";
  49.  
  50. //swapNums(firstNum, secondNum);
  51.  
  52. //cout << "After swap: " << "\n";
  53. //cout << firstNum << " " << secondNum << "\n";
  54.  
  55. //..................pass Array..........................//
  56.  
  57. // how to pass an array to a function in C++? ...................................................... You can pass an array to a function by specifying the name of the array without any square brackets. The function will receive a pointer to the first element of the array.
  58.  
  59.  
  60.  
  61. //int myNumbers[5] = { 10, 20, 30, 40, 50 };
  62. //printArray(myNumbers, 5);
  63.  
  64. //...................recursion..........................//
  65.  
  66. //int result = 1;
  67. //result = sumFrom1toN(5);
  68. //cout << "The sum from 1 to 5 is: " << result << "\n";
  69.  
  70. //// Search for recursion on google ...
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Sweden
India
Norway
USA