Function return type & variable initialisation in C++

The published C++ doesn't allow main() to have void type. 

1
2
3
4
5
6
7
#include <iostream>

void main()
{

   
}


Output:

1
2
Line 3: error: '::main' must return 'int'
compilation terminated due to -Wfatal-errors.


So, always return type of main should be integer in C++. 

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main()
{
   int i = 10;
   int j(20);

   cout << "Value of i " << i << " j " << j << endl;
  
   return 0;
}


Output:

1
Value of i 10 j 20








Comments