DEV Community

Cover image for Lesson 1 - Introduction to C++ Programming Language
lobarim
lobarim

Posted on

Lesson 1 - Introduction to C++ Programming Language

Today, we began the foundation course for learning to code.

By definition, the term code is mysterious. It indicates a technical method of communication that computers, not people, are intended to understand.

As a beginner, we start with a C++ Programming Language.

C++ is a middle-level language, which allows it to program low-level (drivers, kernels) and even higher-level applications (games, GUI, desktop apps etc.). 

We firstly learned how to write these basic codes and how to decipher them.

Image description

Each of these codes has a distinct meaning.

For example:

<iostream>
Enter fullscreen mode Exit fullscreen mode

is the library header file which contains all the functions of program like cout, cin etc. and

#include
Enter fullscreen mode Exit fullscreen mode

tells the preprocessor to include these library header file in the program.

In order to read or write to the standard input/output streams, you need to include it.

Also it can be written on these forms:

Image description

That program will not compile unless you add #include

The second line isn't necessary:

using namespace std;
Enter fullscreen mode Exit fullscreen mode

That tells the compiler that symbol names declared in the std namespace are to be brought into the scope of your program, therefore you can omit the namespace qualifier and write:

#include <iostream>
using namespace std;

int main()

{
    cout << "Hello, World!" << endl;
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

You can now use the shorter name cout instead of the fully qualified name std::cout to refer to the output stream.

When it comes to

int main()

{

……..
………

return 0;

}

Enter fullscreen mode Exit fullscreen mode

We need to understand that “main” is a function which exists in each and every C++ code we will ever write. Without a main function, our code would not work.

Everything written inside the {..} will be executed

There are only two statements in the above code snippet. We need memory to run any code. "int" denotes that it is of the integer type. When we use "int," we take the memory that an integer would require. The code uses the "borrowed" memory until the execution is completed. When the execution is finished, we say return 0. As you can see, zero is an integer, so by saying return 0, you are returning an integer, i.e. the "int" that the main was using.

To finish, the last things that we learned is the difference between endl and \n. They both serve he same purpose in C++ – they insert a new line.

For example:

cout << "Hello World!\n";

or 

cout << "Hello World!"<< endl;

Enter fullscreen mode Exit fullscreen mode

The only difference is that <<endl flushes the output buffer, and '\n' doesn't.

@dawroun

Top comments (0)