What is "void" really? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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#.

12th Aug 2018, 3:40 PM
Keith Ivan Ricahuerta
Keith Ivan Ricahuerta - avatar
105 Answers
+ 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?
12th Aug 2018, 3:51 PM
Jan Štěch
Jan Štěch - avatar
+ 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
13th Aug 2018, 9:42 AM
Light
Light - avatar
+ 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'.
26th Aug 2018, 12:23 AM
Shams Awais
Shams Awais - avatar
+ 29
void is return type like int,string,float but void is a return type dont have value
25th Aug 2018, 3:11 PM
Real Gutch
Real Gutch - avatar
+ 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"..
25th Aug 2018, 3:09 PM
Yash✳️
Yash✳️ - avatar
+ 14
void? kuch v nahi hai
26th Aug 2018, 2:19 PM
👑Mahesh Khatri👑
👑Mahesh Khatri👑 - avatar
+ 12
void means no value. void return type method return nothing.
12th Aug 2018, 7:10 PM
Rakesh Kumar
Rakesh Kumar - avatar
+ 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
25th Aug 2018, 3:06 PM
Deepak
Deepak - avatar
+ 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
25th Aug 2018, 10:01 PM
D_Stark
D_Stark - avatar
+ 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
26th Aug 2018, 2:01 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 10
actually void is space between two things
26th Aug 2018, 1:58 PM
Charan Leo25
Charan Leo25 - avatar
+ 9
its means no return
25th Aug 2018, 3:08 PM
Real Gutch
Real Gutch - avatar
+ 9
void is a return type which returns no value...
25th Aug 2018, 5:15 PM
$oftware Geek
$oftware Geek - avatar
+ 9
void is a return type it's just does not return any value or have any
26th Aug 2018, 4:13 AM
Arvind Raj
Arvind Raj - avatar
+ 9
if your function return void you can't assign this void to any variable or use this function as argument for another function
20th Sep 2018, 8:46 PM
Lev Tolstoy SPB
Lev Tolstoy SPB - avatar
+ 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
25th Aug 2018, 3:24 PM
Aarav Raj
Aarav Raj - avatar
+ 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😃😃
25th Aug 2018, 4:11 PM
Param Kansagra
Param Kansagra - avatar
+ 8
void is a return type which returns no value...
25th Aug 2018, 5:15 PM
$oftware Geek
$oftware Geek - avatar
+ 7
void is basically return type method with no value in c, it means 'nothing' or 'no type' we can say its null
25th Aug 2018, 6:17 PM
Mohammad Anas
Mohammad Anas - avatar
+ 7
void indicates that the method does not need to return a value
25th Aug 2018, 6:19 PM
Mouadh Ben Abdallah
Mouadh Ben Abdallah - avatar