+ 2
Why there is no semicolon at the end of the line static void main()
3 Answers
+ 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.
+ 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.
+ 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