C++
by
Dr. Rachana Kamble
Technocrats Group of Institutions
Technocrats Group Campus, BHEL, Bhopal - 462021 MP, India
Phone : +91-755-2751679
e-mail:
[email protected] | website: www.technocratsgroup.edu.in
Introduction of Programming Language
• A programming language is a set of commands,
instructions, and other syntax use to create a software
program.
• Languages that programmers use to write code are called
"high-level languages."
• This code can be compiled into a "low-level language,"
which is recognized directly by the computer hardware
Machine Language
• Machine language is the language understood by a computer.
• It is very difficult to understand, but it is the only thing that
the computer can work with.
• All programs and programming languages run programs in
machine language.
• Machine language is made up of instructions and data that are
all binary numbers.
• Machine language is normally displayed in hexadecimal form
so that it is a little bit easier to read. Assembly language is
almost the same as machine language, except that the
instructions, variables and addresses have names instead of
just hex numbers
What Is an Assembly Language?
• An assembly language is a type of low-level programming
language that is intended to communicate directly with a
computer's hardware.
• Unlike machine language, which consists of binary and
hexadecimal characters, assembly languages are designed to
be readable by humans.
HIGH LEVEL LANGUAGE
• High-level languages are designed to be easy to read and
understand.
• This allows programmers to write source code in a natural
language, using logical words and symbols.
• For example, reserved words like function, while, if,
and else are used in most major programming languages.
Symbols like <, >, ==, and != are common operators.
Examples of high-level languages include
• C++, Java, python, .Net etc.
C++ Programming training
• C++ is an object-oriented programming language.
• It is an extension to C programming.
What is C++
• C++ is a general purpose, case-sensitive, it supports object-
oriented, procedural and generic programming.
Object-Oriented Programming (OOPs)
C++ supports the object-oriented programming, the four major
pillar of object-oriented programming (OOPs) used in C++ are:
Inheritance
Polymorphism
Encapsulation
Abstraction
C++ Standard Libraries
Standard C++ programming is divided into three important
parts:
The core library includes the data types, variables and literals,
etc.
The standard library includes the set of functions
manipulating strings, files, etc.
The Standard Template Library (STL) includes the set of
methods manipulating a data structure.
Usage of C++
By the help of C++ programming language, we can develop
different types of secured and robust applications:
Window application
Client-Server application
Device drivers
Embedded firmware etc
C++ Program
All C++ programs are given with C++ compiler so that you can
easily change the C++ program code.
File: main.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello C++ Programming";
return 0;
}
A detailed explanation of first C++ program is given in next
chapters.
C vs. C++
What is C?
• C is a structural or procedural oriented programming
language which is machine-independent and extensively
used in various applications.
• C is the basic programming language that can be used to
develop from the operating systems (like Windows) to
complex programs like Oracle database, Git, Python
interpreter, and many more.
• C programming language can be a forms the base for other
programming languages.
• If we know the C language, then we can easily learn other
programming languages.
• C language was developed by the great computer scientist
Dennis Ritchie at the Bell Laboratories.
What is C++?
• C++ is a high level programming language developed by
Bjarne Stroustrup at Bell Labs in 1980.
• C++ is an object-oriented programming language, so it is
safer and well-structured programming language.
C vs C++
The following are the differences between C and C++:
Definition
• C is a structural programming language, and it does not
support classes and objects, while C++ is an object-oriented
programming language that supports the concept of classes
and objects.
No. C C++
1) C follows the procedural style C++ is multi-paradigm. It supports
programming. both procedural and object oriented.
2) Data is less secured in C. In C++, you can use modifiers for class members
to make it inaccessible for outside users.
3) C follows the top-down approach. C++ follows the bottom-up approach.
4) C does not support function C++ supports function overloading.
overloading.
5) In C, you can't use functions in In C++, you can use functions in structure.
structure.
6) C does not support C++ supports reference variables.
reference variables.
7) In C, scanf() and printf() are C++ mainly uses stream cin and cout to
mainly used for perform input and output operations.
input/output.
8) Operator overloading is not Operator overloading is possible in C++.
possible in C.
9) C programs are divided C++ programs are divided into functions
into procedures and and classes.
modules
10) C does not provide the C++ supports the feature of namespace.
feature of namespace.
11) Exception handling is not C++ provides exception handling using Try
easy in C. It has to perform and Catch block.
using other functions.
12) C does not support the C++ supports inheritance.
inheritance.
C++ history
• C++ programming language was developed in 1980 by Bjarne
Stroustrup at bell laboratories of AT&T (American Telephone &
Telegraph), located in U.S.A.
• Bjarne Stroustrup is known as the founder of C++ language.
C++ Features
C++ is a widely used programming language.
1) Simple
C++ is a simple language because it provides a structured approach
(to break the problem into parts), a rich set of library functions,
data types, etc.
2) Abstract Data types
In C++, complex data types called Abstract Data Types (ADT) can be
created using classes.
3) Portable
C++ is a portable language and programs made in it can be run on
different machines.
4) Mid-level / Intermediate programming language
C++ includes both low-level programming and high-level
language so it is known as a mid-level and intermediate
programming language. It is used to develop system applications
such as kernel, driver, etc.
5) Structured programming language
C++ is a structured programming language. In this we can divide
the program into several parts using functions.
6) Rich Library
C++ provides a lot of inbuilt functions that make the development
fast. Following are the libraries used in C++ programming are:
<iostream>
<cmath>
<cstdlib>
<fstream>
7) Memory Management
• C++ provides very efficient management techniques.
• The various memory management operators help save the
memory and improve the program's efficiency.
• These operators allocate and deallocate memory at run time.
• Some common memory management operators available C++
are new, delete etc.
8) Quicker Compilation
C++ programs tend to be compact and run quickly. Hence the
compilation and execution time of the C++ language is fast.
9) Pointer
C++ provides the feature of pointers. We can use pointers for
memory, structures, functions, array, etc. We can directly interact
with the memory by using the pointers.
10) Recursion
In C++, we can call the function within the function. It provides
code reusability for every function.
11) Extensible
C++ programs can easily be extended as it is very easy to add new
features into the existing program.
12) Object-Oriented
In C++, object-oriented concepts like data hiding, encapsulation,
and data abstraction can easily be implemented using keyword
class, private, public, and protected access specifiers. Object-
oriented makes development and maintenance easier.
13) Compiler based
• C++ is a compiler-based programming language, which means no
C++ program can be executed without compilation.
• C++ compiler is easily available, and it requires very little space
for storage.
• First, we need to compile our program using a compiler, and
then we can execute our program.
14) Reusability
• With the use of inheritance of functions programs written in C++
can be reused in any other program of C++.
• You can save program parts into library files and invoke them in
your next programming projects simply by including the library
files.
• New programs can be developed in lesser time as the existing
code can be reused.
15) National Standards
C++ has national standards such as ANSI.
16) Errors are easily detected
It is easier to maintain a C++ programs as errors can be easily
located and rectified. It also provides a feature called exception
handling to support error handling in your program.
17) Power and Flexibility
• C++ is a powerful and flexible language because of most of
the powerful flexible and modern UNIX operating system is
written in C++.
• Many compilers and interpreters for other languages such as
FORTRAN, PERL, Python, PASCAL, BASIC, LISP, etc., have been
written in C++.
• C++ programs have been used for solving physics and
engineering problems and even for animated special effects
for movies.
18) Redefine Existing Operators
C++ allows the programmer to redefine the meaning of existing
operators such as +, -. For Example, The "+" operator can be
used for adding two numbers and concatenating two strings.
19) Modelling real-world problems
The programs written in C++ are well suited for real-world
modeling problems as close as possible to the user perspective.
20) Clarity
The keywords and library functions used in C++ resemble
common English words.