introduction of c++

Introduction of C ++-: C + + is an object oriented programming language it was developed by Bjarne Stroustrup at AT & T Bell Laboratories in  Murray Hill ,New Jersey ,USA ,in the early 1980s . Stroustrup,an admiral of simula67 and strong supporter of C,  Wanted to combine the best of both the language and create a more powerful language that could support object oriented programming features and still retain the power and Elegance of C.  The result was C + +.  Therefore C + + is an extension of C with a major edition of the class construct  feature of Simula 67 since the class was a major addition to original C language. Stroustrup initially called the new new language C with classes . However, letter in 1983, the name was changed to C + +. The idea of C++ comes from the C increment operator + +, thereby suggesting that C + + is an augmented (incremented) version of c.

        During the early 1990’s the language underwent a number of improvements and changes . In November 1997, the ANSI/ISO standards committee standardised these changes and added several new features to the language specifications.
.           C++ is a superset C programming. Most of what we already know about C applies to C++  also. Therefor, almost all C programs are also C ++ programs. However there are a few minor differences that will prevent a C program to run under C++ compiler. We shell see these defenses later as and when they are encountered.

     The most important facilities C++ adds on the C are classes, inheritance, functions overloading, and operator overloading. These features enable creating of abstract data type, inherit properties from existing data type and support polymorphism, thereby making C++ a truly object oriented language.
The object oriented features in C + + allow programmers to build large programs with clarity, extensibility and ease of maintenance, incorporating the spirit and efficiency of C. The addition of new features has transformed C from a language that currently facilitates top-down, structured design, to one that provides bottom-up, object oriented design.

Applications of C + +

C + + is a versatile  language for handling very large programs. It is suitable for Virtually any programming task including development of editors, compilers, databases, communication systems and any Complex real life application systems.

  •  Since C + + allows us to create hierarchy-related objects, we can build special object oriented libraries which can be used later by many programmers.
  •  While C++ is able to map the real world problem properly, the C  part of C++  gives the language the ability to get close to the machine level details.
  •  C++ programs are easily mentionable and Expendables. When  a new feature needs to be implemented, it is very easy to add to the existing structure of an object.
  •  it is expected that C++ will replace C as a general purpose language in the near future.


A Simple C ++ program example 

Let us begin with a simple example of a c ++ program that prints a string on the screen .

#include <iostream> // include header file
Using namespace std;
Int main()
Cout << “C++ is better than C.\n”; // C++ statement
Return 0;
} // End of example

This simple program demonstrates several C++ features.
Program features of c++

Like C , the C++ program is a collection of functions. The above example contains only one function, main(). As usual, execution begins at main(). Every C++ program must have a main().

C++ is a free form language. With a few exceptions, the compiler ignores carriage returns and white spaces. Like C the C++ statements terminate with semicolons.

C++ introduces a new comment symbol // (double slash). Comments start with a double slash symbol and terminate at the end of the line. A comment may start anywhere in the line and whatever follows till the end of the line is ignored. Note that there is no closing symbol.

The double slash comment is basically a single line comment. Multiline comments can be written as follows:

// This is an example of
// C++ program to illustrate
// Some of its features
The C comment symbols/*, */ are still valid and are more suitable for multiline comments. The
following comment is allowed:
/* This is an example of
C++ program to illustrate
Some of its features

We can use either or both styles in our programs. However, remember that we can not insert a // style comment within the text of a program line. For example, the double slash comment cannot be used in the manner as shown
for(j=0; j<n; /* loops n times */ j++

Output Operator

Only statement in program is an output statement the statement
cout << “C++ is better than C.”;

causes the string in quotation marks to be displayed on the screen . This statement introduces to new features, cout and << . The identifier cout (, pronounced as ‘C out’) is a predefined  object that represents the standard output stream in C + +. Hear ,the standard output stream represents the screen. It is also possible to redirect the output to other output devices. We shall later discuss streams in detail.

The object cout has a simple interface. In string represents a  string variable, then the following statement will display its contents.
cout  <<  string;

We may recall that the operator << is the bitwise left shift operator and it can still be used for this purpose. This is an example of how one operator can be used for different purpose, depending on the context. This concept is known as operator overloading, an important aspect of polymorphism. It is important to note that we can still use printf() for displaying an output. C++ accepts this notation. However, we will use cout << to maintain the spirit of C + +.

The iostream File

We have used the following #include directive in the program:
#include <iostream>

This directive causes the preprocessor to add the contents of the iostream file to the program. It contains declaration for the identifier cout and the operator << . Some old versions of C + + use a header file called iostream.h. This is one of the changes introduced by ANSI C++. (We should use iostream.h if the compiler does not support ANSI C++ features.
The header file iostream should be included at the beginning of all programs that use input/output statements. Note that the naming conventions for header file may vary. Some implementations use iostream.h pp;  yet others iostream.hxx. We must include appropriate header files depending on the contents of the program and implementation.

Leave a Comment