Printing out a function

Hello!
I'm just trying to understand passing by value and passing by reference but while i was writting the code another question came up. If I try to print out the value like this: cout << passbyV(a); it gives me a mistake: "no match for 'operator<<' in std::cout << passbyV(a)". What is the reason for this mistake? I already have the correct code, i was trying to write my own. The correct code is: passbyV(a); passbyR(b); cout << a << endl; cout << b << endl;

Thank you in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  void passbyV(int x);
  void passbyR(int *x);

int main(){
    int a = 1;
    int b = 1;

    cout << passbyV(a) << endl;
    passbyR(&b);
}

void passbyV(int x){
    x = 50;
}

void passbyR(int *x){
    *x = 30;
}
passbyV(a) is void and returns nothing to cout.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int passbyV(int x);
int* passbyR(int *x);

int main(){
    int a = 50;
    int b = 10;

    cout << passbyV(a) << endl;
    cout << *(passbyR(&b)) << endl;
}

int passbyV(int x){
    return(x);
}

int* passbyR(int *x){
    return(x);
}
Last edited on
Thanks a lot! :)
Topic archived. No new replies allowed.