Void | SoloLearn: Learn to code for FREE!



How using void?

2/5/2018 1:32:05 PM

Михаил Попов

5 Answers

New Answer


if you declare your method as void, you don't want it to return any value.


If you use void in your method declaration, it means that it won't return anything.


and what should he return?


Can you please send then absolutely any code in which Write what it will do.


when you make a function, it has a return type. for example int myFunction(){ int a=5; return a; } The above code will return the variable 'a' that is 5 (an integer) when the function is finished running successfully. however this function will only return integers. It cannot return any other type of variable (string, bool, double, float, etc.) So what is a void? a void is a function that does not return anything, for example void printHello(){ cout<<"Hello!"<<endl; } the function will print out "Hello!" but will not return anything. in other words, no "return [something] at the end. hope this makes it clear.