Clarification about a few things relating to functions in C++?
I wanted to clarify 2 things which I am not sure about while going through a C++ tutorial:
-
Is the following correct: when you have a void type function versus another type (such as int or float), the void function does not require a return statement, though if there is one, you CANNOT specify a return expression? for example: a void type function may have either: no return type statement OR just "return;", but may not have "return x;" where x is ANY expression, such as a constant or a variable used in the function. Alternatively, any other function type (or at least the ones I have been made aware of this far, which are basically the variable types, such as float, int, char) MUST have a "return x;" type statement where x matches the function type specified.
-
Is the following also correct: from what I have tried quickly, it seems that if you specify a variable in one function, it WILL NOT be recognized in any other function? So if I say "int x = 5;" in one function in my code, "x" will not be recognized as 5, or even an integer in any other part of code EXCEPT FOR in the function it is initialized in.
If I could get confirmation about these few things (and feel free to mention any other similar or related things that I may come across relating to these) I would really appreciate it! thanks in advance :)
Posted Dec 29, 2011, 5:11 AM UTC