| Austin J (20) | |
| Hi, sorry for asking such a basic question, but when is it necessary to use void? I have a book and it says very little about void except in a table on data and for it says "none". | |
|
|
|
| inc0001 (10) | |||
|
Void is usually used in functions and it returns no value(not quite sure what it really means)... Example:
Ps: Ignore the text, I directly copied it from one of my own projects. | |||
|
Last edited on
|
|||
| TheIdeasMan (1760) | |||
void as a return type for a function means that the function does not return any value- so the function does not require a return statement:
It can also be used to specify that a function does not have any parameters, but this has not been a requirement for C++ for a long time. You can just leave the parentheses empty as in the code snippet above. There is also pointer to void, but that is mainly a C language thing as far as I can tell. I don't have a great deal of knowledge on that though. Hope this helps. @inc0001 As I said, line 10 in your code isn't needed. We were posting at the same time. | |||
|
Last edited on
|
|||
| shaund1 (7) | |
| Not only is it not required void CANNOT --- return any time unless the compiler is configured | |
|
|
|
| cire (2362) | ||
It's unclear what you're trying to say here. If you are trying to say that a compiler must be specially configured for a function with a void type to return, you are mistaken. And as far as not being required for a function that doesn't return a value, yes it is required. | ||
|
|
||
| Chervil (1206) | |
The return statement can be especially useful if the function may exit at multiple points.
| |
|
Last edited on
|
|