Monday 2 October 2017

Introduction to C++ Programming Language - Geeks4Coding

Introduction to C++ Language


C++ Programming Language


      C++ is a general purpose programming language and widely used for competitive programming. C++ language is an extension to C language and was developed by Bjarne stroustrup at bell labs. C++ has both high level and low level language features.

C++ is as the name says an extension of the C language. Back in the 1980s it was generally referred to as ‘C with classes’ (just like Objective-C, really), but it’s much more than that.

In addition to having a far more extensive standard library (STL strings are so nice after using C strings for ages), it also comes with a meta-programming language which puts the pre-processor of C/C++ to shame: template-programming.

While C is very powerful, it’s also deliberately very simple, or ‘high-level assembly’ as it’s often referred to. This also means that you’re basically just programming the hardware. C++ allows you to explore far more abstract programming concepts far more easily, as anyone who has ever has wrangled with a template-based project can attest to.

Basically, C is for when you are bootstrapping an OS, writing code for an MCU or trying to optimise the heck out of some drivers. C++ is for when you try to do anything that’d take half a lifetime to accomplish in C, or be impossible in another language.

C++ Language has a lot of features which are not in C :
  • C++ is Object-Oriented.
  • It has the concept of multiple inheritance, polymorphism and encapsulation.
  • All the OOPS features in C++ like Abstraction, Encapsulation, Inheritance etc makes it more worthy and useful for programmers.
  • C++ supports and allows user defined operators Operator Overloading,Virtual Function and function overloading is also supported in it. 
  • Bottom up approach adopted in Program Design. 
  • Stronger Type Checking in C++. 
  • Exception Handling is there in C++.
  • The Concept of Virtual functions and also Constructors and Destructors for Objects.
  • Inline Functions in C++ instead of Macros in C language. Inline functions make complete function body act like Macro, safely.
  • Variables can be declared anywhere in the program in C++, but must be declared before they are used.
  •  C++ is a powerful, efficient and fast language. It finds a wide range of applications – from GUI applications to 3D graphics for games to real-time mathematical simulations.


                           C++ runs on lots of platform like Windows, Linux, Unix, Mac etc. Before we start programming with C++. We will need an environment to be set-up on our local computer to compile and run our C++ programs successfully.If you do not want to setup a local environment you can also use online IDEs for compiling your program.

Using IDE: IDE stands for Integrated Development Environment. IDE is a software application that provides facilities to a computer programmer for developing softwares. There are many online IDEs available which you can use to compile and run your programs easily without setting up a local development environment.

Setup local environment
For setting up your own personal development environment on your local machine you need to install two important softwares:
  1. Text Editor: Text Editors are type of programs used to edit or write texts. We will use text-editors to type our C++ programs. The normal extension of a text file is (.txt) but a text file containing C++ program should be saved with ‘.CPP’ or ‘.C’ extension. Files ending with extension ‘.CPP’ and ‘.C’ are called source code files and they are supposed to contain source code written in C++ programming language. These extension helps the compiler to identify that the file contains a C++ program.
    Before beginning programming with C++, one must have a text-editor installed to write programs.
  2. C++ Compiler: Once you have installed text-editor and typed and save your program in a file with ‘.CPP’ extension, you will need a C++ compiler to compile this file. A compiler is a computer program which converts high-level language into machine understandable low-level language. In other words we can say that it converts the source code written in a programming language into another computer language which computer understands.For compiling a C++ program we will need a C++ compiler which will convert the source code written in C++ into machine codes. Below is the details about setting up compiler on different platforms.
Windows Installation: There are lots of IDE available for windows operating system which you can use to work easily with C++ programming language. One of the popular IDE is Code::Blocks. To download Code::Blocks you may visit this link. Once you have downloaded the setup file of Code::Blocks from the given link open it and follow the instruction to install.

  • After successfully installing Code::Blocks, go to File menu -> Select New and create an Empty file.
  • Now write your C++ program in this empty file and save the file with a ‘.cpp’ extension.
  • After saving the file with ‘.cpp’ extension, go to Build menu and choose the Build and Run option. 
Follow below picture for using Codeblock:

Using Codeblock
Using Codeblock

    Writing first C++ program


    Output:
    Hello World

     
    First C++ program







    No comments:

    Post a Comment

    Thank you for your Time. Keep Learning

    Geeks4Coding

    Contributors

    Popular Posts