Introduction to C++ for Competitive Programming.

C++ is by far the most popular language of choice for competitive programmers across the world as it is usually faster than Java and Python, and most of the resources are available in C++. C++ also has a vast library called STL(Standard Template Library) which makes life a lot easier for competitive coders. GNU/G++ is the standard compiler for C++ and C++ 14 is the latest updated version of C++ available on online judges. So let us start exploring C++

If you are very new to computer programming then please go through this Video from Youtube which gives an introduction and history of c++.



Things we will be discussing here,
  • First Program in C++
  • Understanding of Syntax used here.
So the below is our first program in C++ using which we will be understanding the basic syntax of C++.


Line 1. Includes the libraries to be used here. Libraries are the collection of the programs written for performing different functions such as cout, main(), return, etc.

Line 2. std is an abbreviation of standard. std is the standard namespace. cout, cin and a lot of other things are defined in it. (This means that one way to call them is by using std::cout and std::cin.)

Line 4. It starts the main function with return type int (Integer).
Line 5. Output the word "Hello World". "\n" is used to print the next output in the new line.
Line 6. Return 'returns' the value to the calling function.(We will be discussing more about this in later article)


Everything which is written by the user to solve problems is inside the main(). It is also called as the driver function as all the function which are made to perform a different function are called inside the main().

Comments in C++
Comments are used to write short explanations or observations concerning the code (can be used anywhere in the program and has no effect on the behavior of the program).

Syntax for comments



Practice Problems

  1. Hello ( HackerEarth )
Summary

So in this, we have discussed the basic syntax of C++, this is also the template code that will be used in every code. In the next, we will be discussing the Data Types in C++.

If there is any error or you have a doubt then do ask them through the comment.
Thank you for Reading

Comments