Hi
So far I have always seen function declarations of user-defined functions being made before the main( ). But I have seen someone who made the declaration within the main( ) for a functions which returns a value? Is this correct? Can we also do this for functions which returns nothing - I mean of void return type?
I don't have a compiler on my computer right now so can't test it? Please help me. Thanks.
where to make function declaration, before main( ), or within main( )?
Started by jackson6612, May 31 2011 09:33 PM
3 replies to this topic
#1
Posted 31 May 2011 - 09:33 PM
I'm an outright beginner, learning C++. Using Win XP Pro and Code::Blocks. Be nice to me, please.:)
|
|
|
#2
Posted 31 May 2011 - 10:19 PM
You may declare functions in many places other than the standard areas (remember declaring is a very simple hint, not a definition of the function), although that is a very poor programming method. Correct or not, headers are usually the correct place to store these declarations.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 01 June 2011 - 11:54 AM
Also you can declare a function with any prototype any where though as already mentioned by Alexander, the only correct way to do this is to use header files.
So
So
void func(void);Can be placed any where inside main, before main or after main (if it is not called in main)
#4
Posted 01 June 2011 - 11:09 PM
Thank you, Alexander, Fayyaz.
Best regards
Jackson
Best regards
Jackson
I'm an outright beginner, learning C++. Using Win XP Pro and Code::Blocks. Be nice to me, please.:)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









