It’s finally time to roll on our sleeves and get our hands dirty, cause the best way to learn anything, is by doing.
So let’s start out by making a x86 architecture based operating system in C++.
Well not really.
Although creating something big like an operating system sounds like a cool thing, making an operating system as your first project is like trying to hack into NASA’s mainframe, when you don’t even know how to switch on a computer. The dumbest thing you can think of.
So before you get too thrilled on making an operating system or making a Watch Dogs killer game, let’s start with the basics of how the language looks like.
To just put it on the face, this is how a basic C++ program would look like:
//I better start typing this stuff /*I love comments so much*/ #include <iostream> using namespace std; int main() { cout << "What the heck is all this stuff?"; return 0; }
This is a basic C++ program which would give you an output “What the heck is all this stuff?”, which is probably what you might be thinking, after looking at this cryptic chunk of text for the first time.
This is basically the program which you’ll be writing in the IDE that we installed in the previous chapter which you can refer to get things started.
Comments
//I better start typing this stuff
/*I love comments so much*/
Both of these lines above are called comments, which are not executed, and is only typed by the programmer to make other people understand what a particular statement does in the code.
Header File
#include <iostream>
This is called a header file, which basically contains different kind of stuff that we might need, to do different things in the program. To be more technical, a header file contains the interface of all kind of functions and classes which we will be using in our program. In this case, we’re ‘including‘ the header file named iostream which basically stands for Input/Output Stream.
Namespace
using namespace std;
This statement mentions that we are going to use the namespace of the ‘std’ class of elements, meaning that we are going use the names of functions, classes, variables that are in the ‘std'(standard library) context.
Main Function
int main(){ . . . return 0; }
In the next line, is what we call the ‘main function’, which is basically where the program starts to execute from. By convention we always make the main function return 0 after everything is done executing, in order to say that everything executed well. In C++, statements are terminated by semicolons(;), similar to a dot(.) in English.
Cout
cout << "What the heck is all this stuff?";
Finally we have the message which we want to be displayed using the cout(console output) stream that is present in the iostream header file.