Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




C++ - BASIC


C++

  1. C++ was one of the oldest language developed by Bjarne Stroustrup.

  2. C++ is a High Level Programming Language.

  3. C++ is easy to read and write.

  4. C++ is a cross-platform language

Why should you learn C++?

  1. Popular language

    C++ is considered as one of the old and popular language in the World.

  2. Easy to learn for C++ and C++ programmers

    As the syntax and features of C++ is quite similar to C# and Java. It becomes easy for C# and Java programmers to learn C++.

  3. Object Oriented Programming Language

    C++ is an Object Oriented Programming Language which provides all the features of Object Oriented Programming Language that gives a proper structure to your project.

First C++ Application


Let us write our first C++ Application which just prints Hello World on the screen.


Example :



#include <iostream>
using namespace std;

int main() {
  cout << "Hello World!";
  return 0;
}


Output :




  Hello World

Let us dissect the above code and understand in detail:

  1. So, in the above code we are printing Hello World using the below statement,

    cout << "Hello World";


    The print statement is quite simple. It is called cout followed by <<. And that's all.

  2. Then we have a line that says return 0.

    return 0;


    Well! For now we don't have to understand, what is return 0. You can simply write it.

  3. The cout or print statement and the return 0 is inside something called as the main() method. The main() method is the entry point of a standalone C++ application.

    So, C++ executes the code written inside the main() method :

    int main() {
    	cout << "Hello World!";
    	return 0;
    }

  4. On the top, we have two lines of code,

    #include 
    using namespace std;


    Once again, you don't have to bother about the above lines. You can just write it. It should be common in all C++ programmes.

  5. And finally, all the statements in C++ must end with a semicolon ;.

Well! A question must be crossing your mind that how come int main() didn't end with a semicolon?


Let us keep it a mystery for now. We will explain in eventually.


Moral of the Story


We have to write all our codes inside the main method.


#include <iostream>
using namespace std;

int main() {
	// OUR CODES SHOULD BE WRITTEN HERE.
return 0;
}

The next thing that comes to our mind is, where do we write the above C++ code? And how do we run it?


Well! We have the answers in the next tutorial.