Search This Blog

Friday, July 15, 2011

How does this work? ( functionName(bool& hi) )




#include 
using namespace std;

void someFunction(bool& a);

int main()
{
bool a = true;

someFunction(a);

if( a )
cout <<"a = true";

else
cout <<"a = false";
}

void someFunction(bool& a)
{
a = false;
}




This will print out "a = false".


bool& a in the someFunction contains a memory address, no?

So how can you take a memory address = value?

Wouldn't that try to change the memory address into false in this case?

http://bit.ly/o5TIqm

No comments:

Post a Comment