WHAT IS C ++?
INTRODUCTION:-
C++, pronounced as “See plus Plus”, is a
powerful computer language. It is the advance version of c language. The c is a
procedural1
language
while the c++ is an object
oriented programming language2.
1.
Procedural language:- Programing language is list/set of
instruction telling a computer what to do step by step and how to perform the
first code to second code.
2.
Object oriented programming language:-
Programming language that represent the concept of “object” that how data
field (attribute that described the object) and associated procedure known as
method. Object which are usually instance of class are used to interact with
one another to design application and computer program.
History
of c++:-
In 1967, BCPL language was developed by Master Martin Richards. The BCPL was used to write operating system and
compilers. After two year, ken Thomson developed
B programming
language .B programming language had advance features as compared with BCPL. The UNIIX
operating system was first developed in B in 1970 at Bell laboratory. Both BCPL and B were
“type-less” languages. Thus each data item in these languages occupied one
“word” in the memory.
In 1972, Dennis Ritche developed C language at Bell laboratory. The C
language was an advance version of B language. It had many important concepts of BCPL and B. New features,
like data typing and many other functions were also include in C. The
next version of UNIX was revised and written in C. C language
was developed as a computer independent3 language.
3.
Independent
language: - A program written in C can be run on any computer.
In early 1980s, C++ was developed by Bjarne stroustrup. It was an extension of C. It was designed for the UNIX system
environment. C++ enabled programmers to improve the quality of code. It
included object oriented programming.
Writing
c++ program:-
The source code of C++ program is stored on disk with file extension .cpp (cpp
stand for c plus plus). The program is stored in a text file on the disk. Any
text editor can be used to write and edit C++ source code.
The Borland C++ and Turbo C++
have their own editors for writing the source
code. The source code is written in the editor and then it is compiled.
The C++ compiler translates a C++ source program into the machine code.
The machine code is called object code. It is stored in a new file with
extension obj. The object code is then linked to the libraries. After linking
the object code to the libraries, an executable program is then run from
operating system command line.
For example, a source code of program in C++ is written and stored on
disk with extension .cpp like first.cpp. After compilation, the object code is saved
in file first.obj. And
the executable code is stored in file first.exe.
Structure
of C++ program:-
A C++ program consists of three
main parts. These are:
·
Preprocessor
Directives
·
The main
() function
·
C++ statements
Preprocessor Directives:-
The instructions that are given to the computer before the beginning of
actual program are called Preprocessor Directives. These are also known as computer
Directives. The Preprocessor directives consist of instruction for the
compiler. The compiler adds special instruction or code from these directives
into the program at time of compilation.
These preprocessor normally start with a number sign (#) and the keyword “include” or “define” .For example,
preprocessor directives are used to include header file in the program.
A program example is given below. The first statement of the program is a
preprocessor directive. This preprocessor directive has been written to include
the header file iostream.h.
Header
file:-
Header file is C++ source file that contains definition of library
function/objects. Header files are added into the program at the compilation of
the program. A header file is added if the function/object defined in it is to
be used in the program.
The preprocessor directives “include” is used to add a header file into the
program. The name of file is written in angle brackets (<>) after
“#include” directive. It can also be written in double quotes.
C++ has a large number of headers file in which library function are
defined. The header file must be included in the program before calling its
function in the program. A single header file may contain a large number of
built-in library functions.
For example, the header file iostream.h has definition of different
built-in input and output object and functions. It is include in the above
program because its object “cout” is used in the program.
#include
< name of the header file >
The main ()
function:-
The “main ()” function indicates the beginning of program .
The “main ()” must be included in every C++ program. When a C++ program
is executed, the control goes to the main () function.
The statements within this function are the main body of the C++ Program.
If main() is not included, the program is not compiled and an error message is
generated.
The syntax of the main () function is:
main ()
{
Program statement…
}
C++ Statements:-
The statement of
program are written under the main () function between the curly braces { }. These
statements are the body of the program. Each statement in C++ ends with
semicolon (;).
C++ is a case sensitive
language. The C++ statements are normally written in lowercase letters but in
some exceptional cases, these can also be written in uppercase.
0 comments:
Post a Comment