+ 2

what is the use of void before the function?

16th Apr 2021, 5:42 PM
Gaurav Kumar
Gaurav Kumar - avatar
10 Respuestas
+ 4
first you need to understand the basic syntax of a function. data_type function_name() { // return if you need to? } data_type is the return type of the function.. that is when your function returns something then it'll be in this type mentioned. But sometime function does not need to return anything so in that case we use the keyword "void" to indicate the return type. eg: // here we return the sum of a and b // so we have int return type // also you can see keyword "return" inside the function block int sum(int a, int b) { return a+b; } // here we don't want to return anything so void is use and also no return keyword inside the function void print_hello() { printf("hello") ; } More? Please search for the answer before you post your question. https://www.sololearn.com/discuss/475396/?ref=app https://www.sololearn.com/discuss/80098/?ref=app https://www.sololearn.com/discuss/180774/?ref=app https://www.sololearn.com/discuss/1596883/?ref=app
16th Apr 2021, 5:49 PM
RKK
RKK - avatar
+ 3
Void is a keyword. It is write before function because it returns nothing.
17th Apr 2021, 1:13 PM
Vamsi Chowdary
Vamsi Chowdary - avatar
+ 1
If your function does not have a return value you use void
18th Apr 2021, 8:21 AM
R.P.
R.P. - avatar
0
In programming languages like C and C++ void means that the function does not return a value...😎
18th Apr 2021, 7:19 AM
Sanjay Kamath
Sanjay Kamath - avatar
0
Hariom gupta sir ure a Piece of shî* if u wanna encourage do it ...else keep quiet never discourage any one
18th Apr 2021, 12:47 PM
kreddyt
kreddyt - avatar
0
void before function tells that no value is returning inside this function
18th Apr 2021, 5:23 PM
Jatin Bisht
Jatin Bisht - avatar
0
In C and C++ programming languages, `void` is used as a return type for a function that does not return a value. When a function is declared with `void` as its return type, it means that the function does not return any value to the caller. For example, consider the following function that does not return any value: ```c++ void print_hello() { printf("Hello, World!\n"); } ``` This function does not return any value to the caller. Instead, it simply prints "Hello, World!" to the console. If we tried to declare this function with a non-void return type, the compiler would generate an error, since the function does not actually return any value. In addition to return types, `void` can also be used as a parameter type for a function. In this case, it means that the function does not take any arguments. For example, consider the following function that takes no arguments: ```c++ void print_hello() { printf("Hello, World!\n"); } ``` Here, the `void` keyword is used to indicate that the function does not take any arguments. Overall, `void` is an important keyword in C and C++ programming languages, as it is used to indicate functions that do not return any values or take any arguments.
25th Apr 2023, 7:33 AM
Ali Akram Marufi
Ali Akram Marufi - avatar
0
It is in order to return nothing at all.
9th Oct 2023, 9:24 PM
Werg Serium
Werg Serium - avatar
- 1
Sir you are botttt
18th Apr 2021, 11:11 AM
Hariom gupta
Hariom gupta - avatar
- 1
Play freefire
18th Apr 2021, 11:11 AM
Hariom gupta
Hariom gupta - avatar