C++ Introduction
C++ Features
C++ Hello World program with explanation
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World"<<endl;
return 0;
}
#include<iostream>
#include This is a pre-processor directive.
iostream is a header file name. In C++ we don’t need to include “.h” extension. Older C++ compilers still need “.h” extension. Newer compilers don’t need that extension. For most of the programmes in C++ we use “iostream”, it provides methods to take the input and print the output to the console.
using namespace std;
namespace is a special keyword used in C++. Here we are using std namespace. The compiler will check for classes, functions in the standard library. All of the standard library definitions are inside namespace std.
If we don’t use standard namespace, you need to write “std” behind every keyword.
std::cout << "Hello World"<<std::endl;
int main()
main() function is the starting point of a C program.
{ … }
They denote function body.
cout<< "Hello World" <<endl;
cout is used to write the output to the console and endl is used to put a new line.
To compile a CPP program in Linux use below command:
g++ hello_world.cpp –o hello_world
to execute use:
./ hello_world
Output:
Hello World
C++ Tokens:
1. Keywords Ex: if, for, while
2. Identifiers Ex: num, name
3. Constants Ex: 10, 20
4. operators Ex: +, /, -
5. Special Symbols Ex: { }, ()