void main c++

Posted under C++ Course On By mohammed.mutawe

void main

It is the main function of each programming language, or it is the special place to call everything that was built in the project, and in fact the main functions are almost not seen in large projects, but when you focus on the code, you can know it and distinguish it from others.

Uses of void main

In fact, this function is the entire program. It is not possible to run any project without going through the main function, even closed source systems all depend on the main function to run their software. the lesson.

 

Types

The word main when defining a function cannot be repeated in lines of code more than once, it is only placed once inside the code and the compiler will automatically understand that the entirety of reading and executing the code will be in that function, and you must call all what you wrote in your pages in this function by:

  • Direct connection to other functions.
  • Connection to objects or classes.

 

Example

Please, to understand the main function well, copy one of the following codes into your code editor.

  • The main function is of type integer.
#include<iostream>
using namespace std;


int main() {

std::cout << "This is returned function main";

    return 0;
}

 

  • The main function is of type void.
#include<iostream>
 using namespace std;

void  main() {

    std::cout << "This is void function main";

}

 

Leave a comment

Your email address will not be published. Required fields are marked *