+ 2
what is the use of void before the function?
12 Answers
+ 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
+ 3
Void is a keyword. It is write before function because it returns nothing.
+ 1
If your function does not have a return value you use void
0
In programming languages like C and C++ void means that the function does not return a value...đ
0
Hariom gupta sir ure a Piece of shĂź* if u wanna encourage do it ...else keep quiet never discourage any one
0
void before function tells that no value is returning inside this function
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.
0
It is in order to return nothing at all.
- 1
Sir you are botttt
- 1
Play freefire