You are on page 1of 5

#include <iostream>

using namespace std;


int main
{
cout<<"Hello World!";
}

ERROR: cannot declare '::main' to be a global variable


int main

ERROR TYPE: Compile-time, Syntactical

EXPLAINATION: This error occured because main is a function and a function name is
succeeded by parenthesis.
The compiler, here, took "int main" as an attempt to declare a global
variable which was in
actuality the main function.

CORRECTION: #include <iostream>


using namespace std;
int main()
{
cout<<"Hello World!";
}

#include <iostream>
using namespace std;
int main();
{
cout<<"Hello World!";
}

ERROR: expected unqualified-id before '{' token

ERROR TYPE: Compile-time

EXPLAINATION: Semicolon represents the end of a line. It is used after a function


decclaration only while
declaring the prototype.

CORRECTION: #include <iostream>


using namespace std;
int main()
{
cout<<"Hello World!";
}
using namespace std;
int main();
{
cout<<"Hello World!";
}

ERROR: 'cout' was not declared in this scope


cout<<"Hello World!";

ERROR TYPE: Compile-time

EXPLAINATION: There are some inbuilt functions in C++, like, cout, cin, etc. for
which necessary header
files are used. We can not access these functions without the
inclusion of the required header file.

CORRECTION: #include<iostream>
using namespace std;
int main();
{
cout<<"Hello World!";
}

/*start of the program


#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World!";
}

ERROR: unterminated comment


/*start of the program

ERROR TYPE: Compile-time, Syntactical

EXPLAINATION: When a comment is to be added, the starting and ending of the comment
must be well defined with
"/*comment*/".

CORRECTION: /*start of the program*/


#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World!";
}

/*start of the program*/


#include <iostream>
using namespace std;
int main()
{
Cout<<"Hello World!";
}

ERROR: 'Cout' was not declared in this scope


Cout<<"Hello World!";

EXPLAINATION: C++ is a case-sensitive language, therefore, the case of the keywords


should always be taken care of.

CORRECTION: /*start of the program*/


#include <iostream>
using namespace std;
int main()
{
cout<<"Hello World!";
}

/*start of the program*/


#include <iostream>
using namespace std;
int main()
{
void i;
cin>>i;
cout<<i;
}

ERROR: variable or field 'i' declared void


void i;

EXPLAINATION: Since a variable stores a value, its data type should be mentioned
always and can not be void.

CORRECTION: /*start of the program*/


#include <iostream>
using namespace std;
int main()
{
int i;
cin>>i;
cout<<i;
}

/*start of the program*/


#include <iostream>
using namespace std;
int main()
{
int i;
int &j;
cin>>i;
cout<<j;
}

ERROR: 'i' declared as reference but not initialized


int &i;

EXPAILNATION: Reference variable is an alias, in other words, it is another name


given to an existing variable,
therefore, it is compulsory to initialize it with the declaration
statement.

CORRECTION: /*start of the program*/


#include <iostream>
using namespace std;
int main()
{
int i;
int &j=i;
cin>>i;
cout<<j;
}

You might also like