Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (jadzia):

In C language, when to use the void function? how to use it? Can you give me some examples. I just need to understand it. Thanks!

OpenStudy (shaik0124):

when to use void function: When u don't want a function to return anything then use void function Example #include<stdio.h> void function(int a,int b) { int x=a+b; printf("The value of x is "); printf("%d",x); } int main() { int x=10,y=20; function(10,20); }

OpenStudy (shaik0124):

#include<stdio.h> int function(int a,int b) { int x=a+b; return x; } int main() { int x=10,y=20; b=function(10,20); printf("The value of b is"); printf("%d",b); } output of this program is- the value of b is 30 In this program function is returning the value of x to main function When ever u dont want function to return anything then use void function

OpenStudy (shaik0124):

Please feel free to contact if u have any doubt

OpenStudy (anonymous):

you make a function void if it doesnt have to return any values.

OpenStudy (anonymous):

you can use 'return' values from functions to return values computed or looked-up from the function, or to report error/success states, etc. "Void" means "nothing" and is used when you don't need your function to return anything.

OpenStudy (jadzia):

oh okay! thank you guys! :)

OpenStudy (e.mccormick):

Just a little tidbit: A lot of functions with no return are actually boolean types. They may simply return true if they succeed and false if they fail. So void is used a lot less than you might think.

OpenStudy (jadzia):

thanks for that additional input :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!