Hello World

Introduction

C++ is a programming language. A multiparadigm, object-oriented, strongly typed programming language. The "Hello World" C++ example is:

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

Explanation

The #include directive on the first line:

#include <iostream>

is the preprocessor directive that includes the iostream header needed for the output. The main() function is the main program entry point. It is of type int and the scope of the function is determined by the {} braces.

int main(){
	// code goes here
}

The cout command outputs the string literal to the standard output using the << operator and is part of the std namespace hence the std::cout syntax. :: is the scope operator. The string literal Hello World! is enclosed in matching double quotes ". Statements in C++ end with a semicolon ;

std::cout << "Hello World!";

Examples

We can output multiple string literals by separating them with the << operator:

#include <iostream>
int main(){
	std::cout << "Hello World!" << " C++ rocks!";
}

We can print a newline character using the std::endl:

#include <iostream>
int main(){
	std::cout << "Hello World!" << std::endl;
	std::cout << "This is a second line." << std::endl;
}

Comments in C++ begin with a double forward slash //:

#include <iostream>
int main(){
	// This line is a comment
}