in

CPP – Overview

C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. This tutorial adopts a simple and practical approach to describe the concepts of C++.

C++ is referred as the middle-level programming language because it uses both high level and low-level programming language.

C++ supports Object Oriented Programming as well as Procedure Oriented Programming.

Features of C++

1. C++ is fast

C++ is extended version of C and the C part of it is very slow.

2. C++ is statically typed

C++ is statically typed programming language. C++ doesn’t allow the compiler to make assumptions about the type of the data. Eg: 10 is different from "10". C++ does that own.

3. C++ is multi-paradigm programming language

C++ supports at least 7 different styles of programming and gives developers the freedom to choose one their will. Unlike(Java & Python), you don’t need to use objects to solve every task.

4. Object-Oriented Programming with C

Object-Oriented Programming helps you to solve a problem intutively. We can divide the complex problems into smaller sets by creating objects. And objects are nothing but instances of the class.

5. Power of STL (Standard Library)

These libraries contains efficient algorithms that you can use extensively while coding. This saves lot of time and programming efforts

Writing basic program in C++

Let’s start with Hello World program.

Learning  C++ programming can be simplified into:

  • Writing your program in a text-editor and saving it with correct extension(.CPP, .C, .CP)
  • Compiling your program using a compiler or online.

The “Hello World” program is the first step towards learning any programming language and also one of the simplest program you will learn. All you have to do is display the message “Hello World” on the screen. Let us now look at the program

// Basic HelloWorld program in C++
/*Another style of commenting
 *used in C
 **/
#include <iostream>
using namespace std;
int main()
{
  cout << "Hello World" << endl;
  return 0;
}
Output: 
Hello World

Understand the program

  • // Two slashes are used for commenting something like in this program i’ve commented about the program. Anything you want to explain in your program whether it is a whole program or single line of code. Using // is C++ style comment but as we know that C++ is a superset of C so it also inherits the properties of C, we can also comment the line or bunch of lines using /**/.
  • #include <iostream> Okay, here the line is starting with a # pound sign and that is called a pre-processor directives. When a program runs the compiler executes the pre-processor and the #include directive tells the compiler that, there is a file iostream which needs to be included in the program. The iostream is a header file which contains the standard Input/Output library functions declaration.
  • using namespace std tell the compiler about the different versions of standard library functions. Here, std is the name of the namespace and we are using this namespace with the help of using keyword.
  • int main() This line is used to declare a function named main which returns data of integer type. A function is a group of statements that are designed to perform a specific task. Execution of every C++ program begins with the main() function, no matter where the function is located in the program. So, every C++ program must have a main() function.
  • cout In C++ cout is used to printing output on the screen we have many different version of cout defined in std namespace. If I dig more deeper in it, cout is an object of a class ostream declared in iostream header file which we learn in coming lessons
  • { and } These two opening and closing braces tells about the scope of a function.

Written by Anandesh

I am a #Linux lover and very much excited about technology and new thing. Love to #read_books. Curiosity is my best teacher. I am still☺️ understanding myself.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Top 10 penetration testing tools in Kali Linux 2017

CPP – Setting Up Environment