Skip to main content

Hello World in C++

By January 2, 2020January 5th, 2020No Comments
A basic Hello World program in C++ consists of the following:
using namespace std; 

int main() {
cout << "Hello World" << "/n";
return 0;
  1. #include<iostream>: C++ gives you libraries to work with instead of having to define functions for standard procedures such outputting some data to the console. One of these is iostream which stands for “Input Output Stream” and contains input and output functions. The “#” or hashtag is the symbol combined with the “include” keyboard is a preprocessor command which will include the iostream header file to be processed before our program compiles and executes as our program needs to use it.
  2. using namespace std: A “namespace is like a region, where we have functions, variables etc and their scope is limited to that particular region.”
  3. int main() {}: This the main function for our program. The way to define a function in c++ is:
return type function_name(parameters{
We have to state what will be returned from the function. In this case it is an “integer” therefore, we return 0, at the end of the function 4. We end statements with a semi-colon ; 5. cout : Pronounced as ” C out”. It is an object of the output stream that is used to show output. We included the iostream header file precisely to use cout 6. << Insertion operator 7. “/n”: Will insert a new line. Not needed but still nice to have 8. return 0; : we return 0 at the end since this function expects a return of an “integer type” point 3 above

Leave a Reply