+ 2

Why there is no semicolon at the end of the line static void main()

1st Apr 2017, 5:47 AM
Rakesh Chandra Dash
Rakesh Chandra Dash - avatar
3 Antworten
+ 19
A semicolon is used to terminate a statement. If you terminate your main function right after calling it, the body wouldn't run. It won't even compile in the first place. Taking for example: for (i = 0; i < 10; i++); { //do something } and for (i = 0; i < 10; i++) { // do something } has totally different meaning.
1st Apr 2017, 5:49 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
SEMI-COLON ( ; ) is ONLY used to terminate a STATEMENT. static void main() is a FUNCTION / METHOD in some languages and only has parentheses/brackets for parameters if they are required and then a pair of opening and closing braces / curly brackets { } for the body of the function / method. Syntax: void myFunction( ){ //Body } All functions / methods in any language are not terminated with/by a SEMI-COLON.
1st Apr 2017, 6:55 AM
Tusiime Innocent Boub
Tusiime Innocent Boub - avatar
+ 1
because Void Main is a Method from where he compiler starts compiling/executing your program.if you put semicolon/terminate your Main method then compiler won't execute your program and as a result it gives error
4th Apr 2017, 2:03 PM
Ashutosh Singh
Ashutosh Singh - avatar