+ 2

I need to know the concept behind using void(), it says the function does not return anything? It does not return what?

why we need void what are the initial conception behind using void.

23rd Jun 2017, 6:19 AM
Rocky
Rocky - avatar
5 odpowiedzi
+ 5
Every function must returns something to the caller, but for certain case, you just need to group your code into a function. And that peace of code doesn't return anything, so, you declare it as return void. Then you don't need to have a return statement in your function.
23rd Jun 2017, 9:00 AM
Bàng Tứ Cường
Bàng Tứ Cường - avatar
+ 4
For example, your function returns the sum of 2 argument passed to it. int sum (int a, int b) { int result = a + b; return result; }
23rd Jun 2017, 9:31 AM
Bàng Tứ Cường
Bàng Tứ Cường - avatar
+ 3
thanks it was helpful . I have another question ,in your comment you have referred"every function must return something" ...can you give me some example of those "something" that functions can return.
23rd Jun 2017, 9:13 AM
Rocky
Rocky - avatar
+ 2
cool now I get it, thank you!!
23rd Jun 2017, 9:33 AM
Rocky
Rocky - avatar
+ 2
you're welcome
23rd Jun 2017, 10:22 AM
Bàng Tứ Cường
Bàng Tứ Cường - avatar