function int SomeInt(){return SomeOtherInt;}
May 26, 2013 at 8:23pm UTC
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 May 26, 2013 at 8:24pm UTC
May 26, 2013 at 8:33pm UTC
Probably something changing value of o;
Post whole program here.
May 26, 2013 at 8:34pm UTC
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 May 26, 2013 at 8:35pm UTC
May 26, 2013 at 8:54pm UTC
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?
May 26, 2013 at 8:56pm UTC
You should call function using (), not just output its address:
std::cout << yourFunction() ;
May 26, 2013 at 8:57pm UTC
hahaha thanks MiiNiPaa , stupid me.
my function was right but i was calling it the wrong way!
May 26, 2013 at 9:02pm UTC
also thanks pro code for your reply
Topic archived. No new replies allowed.