Hello friends, today we start our journey of demystifying the world of C++ programming language ☺️ . Those who have been with me on Python tutorial , and C tutorial , know that I believe in getting down to work right away . In this blog, we’ll be learning how simple it is to write a basic C++ program and see how it runs ☺️ .
2. First C++ program
By now, you are already aware of how a terminal is used to write and run any code. Lets recollect those steps again ☺️ .
1.Open a terminal window on your linux/mac machine. If you are using Windows, you’ll probably need Visual Studio IDE .
2. create a start.cpp file using a vi editor and write the code:
using namespace std;
cout<<“Lets have fun with C++.”<<endl;
3. Compile this file using g++ compiler.
4. This will create a default executable file a.out. Run this executable as shown below.
And the output displayed will be
$Lets have fun with C++.
Well, we have successfully created our first software app using C++. Congratulations 🙂 .
3. Some important points
- Comments: comments in C++ can be C style ( /**/) , or using two back slashes ( // ) .
- Cout: cout is used for writing anything on the console/terminal. For eg. ‘ cout << “Hi”<<endl; ‘ will print Hi as output.
- Data types: Just like C, C++ also has some basic data types like int, float, char etc .To know more about them, see my C tutorial. Structures and enum are some of the user defined types.
- Statements: C++ also has if statements, switch, while, for statements. You can know more about them in my C tutorial
Friends, I am sure you would be feeling confident about C++ by now ☺️ . In our next blog, we will start with core C++ concepts like classes, inheritance etc.
Keep learning and keep practicing ☺️ .