+ 2
Void
How using void?
5 Antworten
+ 4
if you declare your method as void, you don't want it to return any value.
+ 2
If you use void in your method declaration, it means that it won't return anything.
+ 2
and what should he return?
+ 2
Can you please send then absolutely any code in which Write what it will do.
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.