Hello friends, hope you all are fine and having fun with your lives. Today, I am going to start a new series of tutorials on C++ Programming. and here’s my first tutorial in this series which is Introduction to C++. I am gonna share a lot of tutorials in this series in future, in which I am gonna explain all about C++. In the initials tutorials, we will cover the basics of C++ Programming and later on we will also cover the pro concepts of C++ Programming.
I am planning on posting around 20 to 30 tutorials in this C++ Programming series, and I am quite sure that it will cover all about C++ and if you are a new learner then it will help you quite a lot.. I have started this series on a request of one of my readers. He suggested me this idea and I like it quite a lot so I though to pursue it. So, today let’s have a look at Introduction to C++, which is quite essential when you are learning a new language you must have its introduction first.
Introduction to C++
- So, now let me first write a simple C++ code, which is gonna print Hello World on the screen.
- Below is given the very basic C++ code and I am gonna explain this code below to give an Introduction to C++ in detail:
using namespace std;
- The above code is the simplest C++ code which is gonna print Hello World on the screen.
- If you read the above code from start then you can see the first statement in the above code is #include <iostream>.
- This first statement is actually including a library in our code file.
- The C++ Compiler already has a lot of libraries in it which we use in our program and can get benefit out of it.
- So, now question is what are these libraries. In any compiler the libraries are designed to create functions and then you can use these functions quite easily.
- Let me explain it in a simple way. For example you want to add two numbers 2 + 2, now you know that the operator + is used for addition but the C++ won’t know about it unless you add the library for math.
- So, here we want to print something on our screen so the C++ will not print it on the screen unless we include this iostream library in it.
- There are many builtin libraries for C++ like conio, arithmetic etc. which we will cover in later tutorials.
- But for rite now, I think you have got the idea what is library, and you really don’t need to know what they are doing. 🙂
- Next line used is using namespace std, its a namespace standard library and you just have to add it as it is in the C++ Library.
- Now next we have the int main(void) command. Its basically a function, which is called the main function.
- In C++ the compiler works top to bottom and the first thing it goes into is the main function so your code must have the main function otherwise it will generate error.
- This Main function is of the form as shown below:
- Now in this main function, you can add anything you wanna add or execute.
- We can create many functions in C++ coding which we will surely cover in coming tutorials but the Main function will always remain single means you can’t add another Main function in it.
- Now after the Main function, we have added a line whose initials are cout, its a c++ commands which is used to print something out and you can see rite after cout we have written a string “Hello World!!!”.
- So, because of cout command our code is printing this Hello World on the screen.
- If you notice we have << these signs between cout and our string to print.
- These signs are called insertion operators.
- At the end of this statement we have endl, which is called end line, and its similar to pressing enter button and after it we have our semi colon (;). Semi colon tells the C++ that our statement is ended.
- So, as a whole its called a statement, and in this statement we first printed out Hello World!!! and then we Entered and finally we added a semi colon to tell our program that statement has ended.
- Now in the next statement we have return 0; , it will return nothing back and will just stop.
- So, in our simple above program we have Main function with two statements and its printing Hello World on the screen.
- It was kind of an Introduction to C++ in which we have designed a small program and then discussed it.
So, that’s all about the introduction to C++, and I hope you guys have learned something out of it. In the coming tutorials, I am gonna post more about C++ and we will cover about variable used in it and how we can make complex codes on c++. So stay tuned and have fun !!! 🙂