0% found this document useful (0 votes)
25 views

Notes 1

Uploaded by

shivamdudeja68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Notes 1

Uploaded by

shivamdudeja68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Difference between

C and C++
Difference between C and C++

Sr. C Language Sr. C++ Language


No
1. C is procedure oriented language 1. C++ is object oriented language.

2. C language is developed by Dennis 2. C++ is an idea of Bjarne Stroustrup


Ritchie.

3. C does not have classes and objects 3. C++ have classes and objects

4. C emphasizes (focuses) on 4. C++ emphasizes (focuses) on data.


functions/procedures

5. Major Input output functions are 5. Major Input output functions are
available in <Stdio.h> header file. available in <iostream.h> header file.
Difference between C and C++
Sr. No C Language Sr. C++ Language

6. Data is not secured. 6. Data is secured.

7. C is a sub of c++ language. 7. C++ is a superset of C language.

8. C uses top-down approach 8. C uses bottom-up approach

9. C is function driven. 9. C++ is object driven.

10. Inline functions are not available in C 10. Inline functions are available.
Difference between C and C++
Sr. No C Language Sr. C++ Language
11. C is a middle level language. 11. C++ is high level language.
12. It does not support reusability 12. It supports reusability of code(Using
Inheritance).
13. It can not model real world applications 13. It is used for real world modeling.

14. Memory management operators are 14. Dynamic memory management


available in C are malloc, calloc etc. operators are "New" and "delete".

15. It does not support the concept of 15. It successfully implements the
polymorphism. concept of polymorphism in the
form of function and operator
overloading.
Difference between C and C++
Sr. No C Language Sr. C++ Language
16. File Extension in C is .c 16 File Extension in C++ is CPP
17. In C Language :- 17. In C++ Language:-
Basic Function used for Input  scanf() Basic Function used for Input  cin>>
Basic Function used for Output  printf() Basic Function used for Output  cout<<
Basic Concepts of
Object-Oriented Programming

Data
Object Classes Abstraction and Inheritance
Encapsulation

Polymorphism
Dynamic Message
Binding Passing
Object

Objects are the basic run-time entities in an object-oriented system.


They may represent a person, a place account, a table of data or any
item that the program has to handle. They may also represent user-
defined data such as vectors, time and list. Programming problem is
analyzed in terms of objects and the nature of communication between
them. Program objects should be chosen such that they match closely
with the real-world objects. Objects take up space in the memory and
have an associated address like a record in Pascal, or a structure in C.
Object

When a program is executed the objects


interact by sending messages to one
another. For example, if “customer” and
“account” are two object in a program, then
the customer object may send a message to
the account object requesting for the bank
balance. Each object contains data, and
code to manipulate the data. Objects can
interact without having to know details of
each other’s data or code.
Classes

Objects contain data and code to manipulate that data. The entire set
of data and code of an objet can be made a user-defined data type
with the help of a class. In fact, objects are variables of the type class.
Once a class has been defined, we can create any number of objects
belonging to that class. Each object is associated with the data of type
class with which they are created. A class is thus a collection of objects
of similar type. For example mango, apple and orange are members of
the class fruit.
Classes are user-defined data types and behave like the build-in types
of a programming language. The syntax used to create an object is no
different than the syntax used to create an integer object in C.
Data
Abstraction and
Encapsulation Data Abstraction

Abstraction refers to the act of representing essential features without


including the background details or explanations. Classes use the concept
of abstraction and are defined as a list of abstract attributes such as size,
weight and cost and functions to operate on these attributes.
Data Encapsulation
The wrapping up of data and functions into a single unit(Called class) is
known as encapsulation. Data encapsulation is the most striking feature
of a class. The data is not accessible to the outside world, and only those
functions which are wrapped ion the class can access it. These functions
provide the interface between the object’s data and the program. The
insulation of the data from direct access by the program is called data
hiding or information hiding.
Inheritance

In OOP, the concept of inheritance provides the idea of reusability. This


means that we can add additional features to an existing class without
modifying it. This is possible by deriving a new class from the existing one.
The new class will have the combined features of both the classes. The
real appeal and power of the inheritance mechanism is that it allows the
programmer to reuse a class that is almost but not exactly, what he wants,
and to tailor the class in such a way that it does not introduce any
undesirable side-effects into the rest of the classes.
Inheritance
Polymorphism

Polymorphism is another important OOP concept. Polymorphism, a


Greek term, means the ability to take more than one form. An operation
may exhibit different behaviours in different instances. The behaviour
depends upon the types of data used in the operation. For example,
consider the operation of addition. For two numbers, the operation will
generate a sum. If the operands are strings, then the operation would
produce a third string by concatenation. The process of making an
operator to exhibit different behaviours in different instances is known as
operator overloading.
Polymorphism

Polymorphism plays an important role in allowing objects having


different internal structures to share the same external interface. This
means that a general class of operations may be accessed in the same
manner even though specific actions associated with each operation may
differ. Polymorphism is extensively used in implementing inheritance.
Dynamic
Binding
Binding refers to the linking of a procedure call to the code to be executed
in response to the call. Dynamic binding (also known as late binding)
means that the code associated with a given procedure call is not known
until the time of the call at run-time. It is associated with polymorphism
and inheritance.
Message
Passing
An object-oriented program consists of a set of objects that
communicate with each other. The process of programming in an
object-oriented language, therefore, involves the following basic steps:
1. Creating classes that define objects and their behavior
2. Creating objects from class definitions and
3. Establishing communication among objects.
In Case of C Language In Case of C++ Language
#include<stdio.h> #include<iostream.h>
#include<conio.h> #include<conio.h>
void main() int main()
{ {
int a,b,c; int a,b,c;
printf(“enter two numbers”); cout<<“enter two numbers”;
scanf(“%d%d”,&a,&b); cin>>a>>b;
c=a+b; c=a+b;
printf(“Total is %d”,c); Cout<<“Total is”<<c;
getch(); getch();
} }
Home Task

1.WAP to calculate area of rectangle


2.WAP to interchange two variables
How to create a class
class <class_name>
{
Access specifiers (public:, Private and Protected)
data_members;
member functions
}
class student
{
int roll_name;
char name[10];
float fees;
public:
void input();
void output();
};

You might also like