Introduction of C++

C++ is an general-purpose, object-oriented programming (OOP) language. C++ is a superset of the C language. It was created by Bjarne Stroustrup at Bell Labs circa 1980s.

Introduction

The programming language C++ evolved from C and was designed by Bjarne Stroustrup at Bell Laboratories in the early 1980s. From the early 1980s through the early 1990s, several C++ compilers were available. Even though the fundamental features of C++ in all compilers were mostly the same, the C++ language, referred to in this book as Standard C++, was evolving in slightly different ways in different compilers. As a consequence, C++ programs were not always portable from one compiler to another.
To address this problem, in the early 1990s, a joint committee of the American National Standard Institution (ANSI) and International Standard Organization (ISO) was established to standardize the syntax of C++. In mid-1998, ANSI/ISO C++ language standards were approved. Most of today’s compilers comply with these new standards. Over the last several years, the C++ committee met several times to further standardize the syntax of C++. In mid-2010, the second standard of C++ was voted on and approved. The main objective of this standard, referred to as C++0X, or tentatively as C++11, is to make the C++ code cleaner and more effective. For example, the new standard introduces the data type long long to deal with large integers, auto declaration of variables using initialization statements, enhancing the functionality of for loops to effectively work with arrays and containers, and new algorithms. However, not all new features of this new standard have been implemented by all the compilers currently available.
C++ is an object oriented programming (OOP) language, developed by Bjarne Stroustrup, and is an extension of C language. It is therefore possible to code C++ in a 'C style' or 'object-oriented style.' In certain scenarios, it can be coded in either way and is thus an effective example of a hybrid language. C++ is a general purpose object oriented programming language. It is considered to be an intermediate level language, as it encapsulates both high and low level language features. Initially, the language was called 'C with classes' as it had all properties of C language with an additional concept of 'classes'. However, it was renamed to C++ in 1983. It is pronounced 'C-Plus-Plus.'
C++ is one of the most popular languages primarily utilized with system/application software, drivers, client-server applications and embedded firmware. The main highlight of C++ is a collection of pre-defined classes, which are data types that can be instantiated multiple times. The language also facilitates declaration of user defined classes. Classes can further accommodate member functions to implement specific functionality. Multiple objects of a particular class can be defined to implement the functions within the class. Objects can be defined as instances created at run time. These classes can also be inherited by other new classes which take in the public and protected functionalities by default.
C++ includes several operators such as comparison, arithmetic, bit manipulation, logical operators etc. One of the most attractive features of C++ is that it enables the overloading of certain operators such as addition.
A few of the essential concepts within C++ programming language include polymorphism, virtual and friend functions, templates, namespaces and pointers.


Borland C++

Borland C++ is a C and C++ programming environment (that is, an integrated development environment) for MS-DOS and Microsoft Windows. It was the successor to Turbo C++, and included a better debugger, the Turbo Debugger, which was written in protected mode DOS. Borland is one company that create compilers. In the past, they released a version of C++ called Turbo C++ that was popular for programming in the DOS environment, and you may find some books still come with that compiler.


Compiler for C++

There are many Compilers available on internet for C-Language like Turbo C++, Borland C++ etc. Download any one and Install.

  • These Tutorials are tested on Borland C++ 5.2.

Comments in C++

//   is used for Single Line Comment
/*   is used for Multiple Line Comment  */
For Example:
//   This is Single Line Comment.
/*    And This
is Multiple Line
Comment.   */

All the code with beginning two slash // are considered comments and do not effect the program.


C++ Program Structure

#include<iostream.h>
#include<conio.h>
void main()
{
//TODO Code Here!!!
getch();
}
  • In C++ programming language all library functions are included in different header files in different categories with .h extension.
  • Header files must be placed at the top of the program. it must be written before program. Sentence that begin with a # are the directives for the preprocessor. this sentence tells compiler to include the header file.
  • C++ input/output streams are primarily defined by iostream, a header file that is part of the C++ standard library (the name stands for Input/Output Stream). In C++ and its predecessor, the C programming language, there is no special syntax for streaming data input or output. Instead, these are combined as a library of functions. Like the cstdio header inherited from C's stdio.h, iostream provides basic input and output services for C++ programs. iostream uses the objects cin, cout, cerr, and clog for sending data to and from the standard streams input, output, error (unbuffered), and log (buffered) respectively. As part of the C++ standard library, these objects are a part of the std namespace.
  • The cout object is of type ostream, which overloads the left bit-shift operator to make it perform an operation completely unrelated to bitwise operations, and notably evaluate to the value of the left argument, allowing multiple operations on the same ostream object, essentially as a different syntax for method cascading, exposing a fluent interface. The cerr and clog objects are also of type ostream, so they overload that operator as well. The cin object is of type istream, which overloads the right bit-shift operator. The directions of the bit-shift operators make it seem as though data is flowing towards the output stream or flowing away from the input stream.
  • conio.h is a C header file used mostly by MS-DOS compilers to provide console input/output. This header declares several useful library functions for performing console input and output from a program.
  • void main( ): All executed statements must be written inside the main body because execution starts from main( ). void main( ) is the point from where program begin their execution. In C language all programs have a main function.
  • All statement ends with semicolon.
  • getch( ) function prompts the user to press a character and that character is not printed on screen, getch header file is conio.h.
  • All C programs save with the extension of .cpp.
  • Before compilation process the code is called source program.
  • After compilation process the program is called object program.
  • comments will be ignored.
  • A file which is ready to execute is called Executable file.
  • Libraries is in C:\BC5\INCLUDE Directory.
  • when U Run the Program then Creating .exe File in C:\BC5\BIN Directory getch() function prompts the user to press a character and that character is not printed on screen, getch header file is conio.h.
  • getch() and putch() are non-standard functions defined in conio.h, mostly used in turbo C/dev C++ environement. getchar() are putchar() are standard functions defined in C standard and they can be used in all environments. Yes, you can certainly write a program without these 4 functions.