C++ - BASIC
C++
-
C++ was one of the oldest language developed by Bjarne Stroustrup.
-
C++ is a High Level Programming Language.
-
C++ is easy to read and write.
-
C++ is a cross-platform language
Why should you learn C++?
-
Popular language
C++ is considered as one of the old and popular language in the World.
-
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++.
-
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:
-
So, in the above code we are printing Hello World using the below statement,
The print statement is quite simple. It is called cout followed by <<. And that's all.
-
Then we have a line that says return 0.
Well! For now we don't have to understand, what is return 0. You can simply write it.
-
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;
}
-
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.
-
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.