Void | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Void

How using void?

5th Feb 2018, 1:32 PM
Михаил Попов
5 Answers
+ 4
if you declare your method as void, you don't want it to return any value.
5th Feb 2018, 1:40 PM
Jonas Schröter
Jonas Schröter - avatar
+ 2
If you use void in your method declaration, it means that it won't return anything.
5th Feb 2018, 1:36 PM
Jonas Schröter
Jonas Schröter - avatar
+ 2
and what should he return?
5th Feb 2018, 1:39 PM
Михаил Попов
+ 2
Can you please send then absolutely any code in which Write what it will do.
5th Feb 2018, 1:42 PM
Михаил Попов
0
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.
5th Feb 2018, 3:39 PM
064XP
064XP - avatar