+ 70
What is "void" really?
I cant really understand, it says void is a method that does not return a value. Do the value are the same like output.Can you pls give me an example of a void? by the way im a begginer and learning C#.
105 ответов
+ 84
Return value and output of the function are different things. Consider following functions:
void printSum(int a, int b){
cout<<a+b;
}
int sum(int a, int b){
return a+b;
}
int main(){
printSum(5, 3);
int num = sum(3, 5);
cout<<num;
}
If a function has a return value the value will "replace" the function invoking statement:
int num = sum(3, 5); --->
int num = 8;
Got it?
+ 35
IN C++ :
Basically, it means "nothing" or "no type"
There are 3 basic ways that void is used:
Function argument: int myFunc(void) -> the function takes nothing. (Optional)
Function return value: void myFunc(int) -> the function returns nothing
Generic data pointer: void* data -> 'data' is a pointer to data of unknown type, and cannot be dereferenced
+ 34
void is a Null data type does not have any value. Here void means 'nothing' if a function does not return any value the its Return type should be void. If a function returns an integer then its return type should be 'int'.
+ 29
void is return type
like
int,string,float
but void is a return type dont have value
+ 14
You could've searched in the search bar (I hope a mod recommends this although this was in "trending now"), this is one of the most common question asked here. Also there are tons of good articles on Google on this topic.
Don't wanna sound rude but that's what a mod or an older user of sololearn app would say for such a question.
I now really want to know what criteria SoloLearn decided a thread is "trending"..
+ 14
void? kuch v nahi hai
+ 12
void means no value. void return type method return nothing.
+ 12
Void is used as a return type in the function. Void doesn't returns a value. But other returns types like int, float, double etc., must return a value
+ 12
i think people get confused with void becuase most of the time a message gets printed to screen when the method is called.
if you dont use the return keyword then your not returning anything so the chances are that method would be void
+ 12
In a simple word, return a value means the output of a method can be assigned to variables.
static int Num(){
return 2;
}
int a=Num();
//so, a is 2 now
+ 10
actually void is space between two things
+ 9
its means no return
+ 9
void is a return type which returns no value...
+ 9
void is a return type
it's just does not return any value or have any
+ 9
if your function return void you can't assign this void to any variable or use this function as argument for another function
+ 8
every function should have return type wheater it is primitive or refrence bt if functions doesnt return anything the keyword use in that place is void so void is keyword
+ 8
Void is a type of data type in various languages. the data type literally means that "no value". but in the languages it is defined as "no return" data type. this is used when you need that the program should not return any value. this can be said as a replace ment of the integer data type in which you have to give the command of return 0 but in the void you need not to do so.
if you liked the expression plz. give an upvote😃😃
+ 8
void is a return type which returns no value...
+ 7
void is basically return type method with no value in c, it means 'nothing' or 'no type' we can say its null
+ 7
void indicates that the method does not need to return a value