function int SomeInt(){return SomeOtherInt;}

i know this is very basic but why does this happen?

1
2
3
4
5
6
7
8
9
int o = 10;
int f()
{
    int k =0;
k=k+o*2;

return k;
}
// f now is 1, why? should not it be 20???lol 


i just don't get this.. also , how can i make f return 20 this way?
Last edited on
Probably something changing value of o;
Post whole program here.
1
2
3
4
5
6
7
8
9
10
11
12

int maine()
{
int k,o;

k=0
o=10

k=k+o*2;

return k;
}


np
Last edited on
compile log warnings:

||In function 'int main()':|

warning: the address of 'int maine()' will always evaluate as 'true' [-Waddress]|
||=== Build finished: 0 errors, 1 warnings (0 minutes, 1 seconds) ===|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;
int maine()
{
int k,o;

k=0;
o=10;

k=k+o*2;

return k;
}

int main()
{
    cout << "value of maine is " << maine << endl;
    return 0;
}



cmd prints: "value of maine is 1"

is this a problem with my compiler?
You should call function using (), not just output its address:
std::cout << yourFunction();
hahaha thanks MiiNiPaa , stupid me.
my function was right but i was calling it the wrong way!
also thanks pro code for your reply
Topic archived. No new replies allowed.