info on "return" order in functions
i discovered these facts about using return in a function while experimenting on my own. take this following function for example:
Code:
char getchen(void);
char getchen(void)
{
char ch;
ch=getche();
return ch;
printf("\n");
}
here i needed the character to be displayed before the carriage return so i thought inserting the return statement at this point would make it work properly. it ended up ignoring everything after the return statement. here is the correct code and explination:
Code:
char getchen(void);
char getchen(void)
{
char ch;
ch=getche();
printf("\n");
return ch;
}
i discovered that the order of return doesnt matter. it always has to be last and all it gives is a reference to the variable that has to be returned. it doesnt necesarily have to be placed where you want the variable to return as i learned from trial and error
hope this was useful to somebody, thx 4 reading. post some replies for me :)