+ 6
What is the difference between int main () and void main()
11 Respuestas
+ 5
int main() must return a value, while void main() doesn't return a value.
Example:
public int myMethod() {
int age = 20;
Return age;
}
void Example:
public void myMethod () {
System.out.println("my name is Trevor");
}
You don't have to place a "return" here because the method didn't mention any "int" or "String" type here.
+ 3
In short it tell the what the program will return in case of int it will return an integer value and in case of void it won't return anything
+ 2
A program has to exit with an exit code, an execution requirement that all processors have. That is why int main is returning 0 in order to mark that it ended execution, ending with -1 would result in forced exitting. Void main is just a function than can be called and int main is the actual code that is being executed when you run the program
+ 1
Nothing will be returned in void while in int the integer value will be returned.
+ 1
Using int main() affect the return function of the program . If void main is used the program or function cannot return it value to other function wheas it can print the result within its function region wheas if int main is used it can return an int value for the same function as well as can pass the value to ofher function
0
main() it returns a value but void main() it doesn't return a value
0
Sava salu
- 1
The difference in parameters. Void functions cannot have parameters whereas others can. Void is mainly used with main function.
Niether does it return any value.