repl.it
@molinitomario/

Functions

C++

my notes

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <cstdlib>

void ByReference(int *reference);
void ByValue(int value);
void Something(int first);
void Something(float first);
// above are osme of the prototypes, this allows us to use these method in the main, even after declaring them after the main

int main() {
  int value = 4;
  ByValue(value);
  std::cout << value << std::endl; // as we can see this does not change the value 
  ByReference(&value);
  std::cout << value << std::endl; // as we can see this DOES change the value of value
  srand(time(0));
  for(int i = 0; i < 10; i++) 
  {
    std::cout << rand();
    std::cout << std::endl;
  }

  for(int i = 0; i < 5; i++) 
  {
    std::cout << 1 + (rand() % 12);
    std::cout << std::endl;
  }
}

void ByReference(int *reference)
{
  // passing a value by reference gives us access to the actual value, since we have the location ot the vlaue via pointer.
  // and as we know already, in order to actually have access to that value you have to dereference the pointer via *
  // so here we are copying the location to the value that was placed inside the paranethesis when this was called
  *reference = -5;
  // we are changing the value in the location that was passed thorugh
}

void ByValue(int value)
{
  // passing by value is not going to change the actual value that was passed, because the value passed is the value that was entered inside the paranthesis value, we literally copied that value and pasted it in the value
  value = 10;
}


// method overloading
// - method overloading only work with methods that have the SAME NAME, and or have different paramters / different paramterse size
void Something(int first)
{
  std::cout << "This was called from the int first method";
  std::cout << std::endl;
}

void Something(float first)
{
  std::cout << "This was called form the float sometthing method";
  std::cout << std::endl;
}





Fetching token
?