Saturday, January 8, 2011

wut?

I just noticed the program I wrote to test returning values from functions has a typo of sorts.

My function:

int MakeChar(char localY)
{
...
}

And in main() I have this:

char MakeChar_Returned = '0';

I then stated:

MakeChar_Returned = MakeChar(mainY);

Which essentially returned an integer value to a character variable!

I thought that wasn't allowed! I fixed it in the program, but this warrants further study. I think I remember that char can take numbers and when you use printf it just converts that number per the ASCII table. I'd have expected the compiler to at least warn me about mismatching return values and variables.

No comments:

Post a Comment