C++

Learn New things from Rixosys

Introduction

What does C++ Programming Language mean?

C++ is a general-purpose object-oriented programming (OOP) language, developed by Bjarne Stroustrup, and is an augmentation of the C language.

C++ is considered to be an intermediate-level language, as it exemplifies both high- and low-level language highlights

 

Where to write C++ code?

For writing Cpp code we have to download a C++ IDE (integrated development environment) such as Eclipse, Netbeans, and CodeBlocks, or you can use a plain text editor such as Notepad++ or VIM.

 

How internally C++ code works?

The compilation of a C++ program involves 3 steps:

Preprocessing: the preprocessor takes a C++ source code file and deals with the #includes, #defines and different preprocessor directives. The output of this step could be a "pure" C++ file without pre-processor directives.

Compilation: the compiler takes the pre-processor's output and produces an object file from it.

Linking: the linker takes the object files made by the compiler and produces either a library or an executable file.

 

Why C++?

C++ is a high-level object-oriented programming language that helps programmers write quick, moveable programs. C++ provides rich library support within the form of standard template Library (STL).

C++ permits you to possess tons of control on however you utilize pc resources, thus within the right hands its speed and skill to cheaply use resources should be ready to surpass different languages.

The C++ language are often used for building higher-level applications with graphics libraries, applications to communicate with network devices and computer network simulators similarly as remote device systems and network management.

Characteristics of C++ :

Simple
Portability
Powerful
Platform dependent
Object oriented 
Case sensitive
Compiler based
Syntax based language
Use of Pointers

First  C++ programming structure :     

// Simple C++ program to display "Hello World"

 #include<iostream>  

using namespace std;

int main()

{

    cout<<"Hello World";

    return 0;

}

 

The “Hello World” program is one of the least complex projects, yet it as of now contains the basic segments that each C++ program has.

we will take a look at the code line by line.

//Simple C++ program to display "Hello World"

A comment line is the first line in our program.

Any line starting with two slash signs (/) will be known as comments and will have no influence 

on the program's actions or outcome. (Words between / * and * / are also known as comments.

Use your program comments to explain challenging sections, but don't overdo it. 

#include<iostream>

The preprocessor compilers use lines starting with a pound sign (#). In this case, the # include directive tells the preprocessor to include the standard file for iostream. This iostream file 

contains declarations in C++ from the basic standard input / output library.

using namespace std;

All the elements of the standard C++ library are declared within what is called a namespace. The namespace with the std name in this case. We placed this line in to state that we will use the features provided in the namespace std. This line of code is used very frequently in C++ programs that use the standard library.

int main()

int is what is called a return value (in this case a type integer. Integer is a whole number). What is being used for will be clarified further down.

This line is employed to declare a function named “main” that returns information of integer type. A function may be a cluster of statements that are designed to perform a selected task. Execution of each C++ program begins with the main() function, notwithstanding wherever the function is located within the program. So, each C++ program should have a main() function.

{ and }:

The opening braces ‘the start of the main function and also the closing braces ‘}’ indicates the ending of the main function. each factor between these 2 includes the body of the main function.

 

cout << “Hello World”;

This line tells the compiler to show the message “Hello Worlld” on the screen. This line is termed a statement in C++. each statement is supposed to perform some task. A semi-colon ‘;’ is employed to finish a statement. Semi-colon character at the end of statement is employed to point that the statement is ending there.

cout is employed to spot the standard character output device that is typically the desktop screen. each issuefollowed by the character “<<” is presented the output device.

return 0;

This is additionally a statement. This statement is employed to return a value from a function and indicates the finishing of a function. This statement is essentially employed in functions to return the results of the operations performed by a function.

Indentation :

As you'll see the cout and therefore the return statement are indented or moved to the right side. this is often done to form the code more clear. during a program as “Hello World”, it doesn't hold much relevance seems however as the programs become more  complicated, it makes the code more clear, less error prone. Therefore, you want to continually use indentations and comments to form the code more clear.