loading

main() function

The Dart’s top-level function is called main(). It is the Dart programming language’s most significant and essential feature. The main() function initiates the programming’s execution. Within a program, the main() function can only be used once.

It is in charge of all execution kinds, including functions, user-defined statements, and library functions. The main() function starts the program, where variables are declared and user-defined executable statements are contained. The arguments for the main function, which returns void, might optionally include a List<String> parameter. Below is a general syntax for the main() function.

Syntax

				
					void main() {  
  // main function body  
}  
				
			

Example

				
					void main()   
{  
  print("Welcome To JavaTpoint");  
    
 }  
				
			

Output

				
					Welcome To JavaTpoint
				
			

Dart Return Value

After analyzing the function statements up to the point where it is called from, the function will occasionally return a value. The function’s result is sent to the function call from the return statement. The return statement is represented by the return keyword. The function returns null if the return statement is omitted. A function may or may not include a return statement, but only one return statement is permitted.

Syntax

				
					return <expression/value>;  
				
			

Dart value with Return Value

The return value syntax is shown below.

Syntax

				
					return_type function_name()   
{  
   //statement(s);  
  return value;  
}  
				
			

This is an explanation of the syntax mentioned above.

function_name: This denotes the name of the function, which can be any kind of recognized identity.

return type: This indicates the function’s return type. Any kind of legitimate data may be used. The return and the function’s return type ought to match.

Example

				
					void main() {  
  int mul(int a, int b){  
        int c = a*b;  
        return c;  
}  
print("The multiplication of two numbers: ${mul(10,20)}");  
}  
				
			

Output

				
					The multiplication of two numbers: 200
				
			
Share this Doc

main() function

Or copy link

Explore Topic