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 the code. Lets recollect those steps again ☺️ .
Open a terminal window on your linux/mac machine. If you are using Windows, you’ll probably need Visual Studio IDE .
create a start.cpp file using a vi editor and write the code:
using namespace std;
cout<<“Lets have fun with C++.”<<endl;
Compile this file using g++ compiler.
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 on the console. 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++ already ☺️ . In our next blog, we will start with core C++ concepts like classes, inheritance etc.
Keep learning and keep practicing ☺️ .