Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (anonymous):

I'm learning C++. I'm confused about return types -- why is it better to use a return type of "void" sometimes, and a return type of "int" other times?

OpenStudy (hba):

void doesn't return anything.so if you don't have to return use void else you could use int/string/boolean if you had to return value from method

OpenStudy (espex):

To expound on the answer given by @hba , you will generally use a function as a tool for manipulating or evaluating data given by another function. If your program has an 'add()' function that adds to variables and returns the sum, you would need to have a "return type" that was descriptive of what the sum was (ie float, double, int). However if you then took that sum and passed it to a 'print()' function, that simply prints to the screen, there is no return value needed and thus your 'print()' would have a return type of 'void'. So one type is not "better" than the other, they are used to describe the data types that are passed between functions.

OpenStudy (anonymous):

Thank you! I understand now. :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!