-
March 29th, 2013, 12:28 PM
#1
Good practice vs bad practice (void vs int functions)
Dear all,
I have a question regarding what a good practice is when working with functions. I am designing a very simple function for addition. I know that what will be the result of that addition is an integer, hence declaring an int function seems to be the right way of doing it. That said, I bumped into the fact that if I declared the same function as void when I run the program it seems to work all right!
here a contrast of what I've seen and found:
-------------------------------------------------------------------------------
int addition (int x, int y, int result){
result = x + y;
cout << "The result of your sum is " << result << endl;
return result;}
-------------------------------------------------------------------------------
void addition (int x, int y, int result){
result = x + y;
cout << "The result of your sum is " << result << endl;}
--------------------------------------------------------------------------------
Question here is: What is the difference and what implications can this kind of practice have in the long run?
Cheers!
FX
Last edited by FelixCast; March 29th, 2013 at 12:30 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|