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

C and C++

C++ is an object-oriented programming language that supports concepts like inheritance, polymorphism, abstraction and encapsulation. It is a mid-level language that can be used to develop applications like games, desktop apps, drivers etc. The key advantages of C++ include efficient memory management, support for procedural and OOPs paradigms, and ability to develop high performance applications.

Uploaded by

Nabin Pradhan
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)
16 views

C and C++

C++ is an object-oriented programming language that supports concepts like inheritance, polymorphism, abstraction and encapsulation. It is a mid-level language that can be used to develop applications like games, desktop apps, drivers etc. The key advantages of C++ include efficient memory management, support for procedural and OOPs paradigms, and ability to develop high performance applications.

Uploaded by

Nabin Pradhan
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/ 13

7.

What is the difference between C and


C++?

C C++

It is a mixture of both
It is aprOcedural
procedural and object
programminglanguage.
oriented programming
In simple words, it does
classes and languages. In simple
not support
words, it supports
objects
classes and objects.
It does not support any
00Ps concepts like
polymorphism, data It supports all concepts
abstraction, of data
encapsulation, classes,
and objects.
It does not support It supports Function and
Function and Operator Operator Overloading
Overloading respectively
It is a function-driven It is an object-driven
language language
12. What is the difference between a while
loop and a do-while loop?

While Loop do-while Loop


While loop is also The do-while loop is
termed an entry termed an exit control
controlled loop loop
If the condition is not Even if the condition is
satisfied the statements not satisfied the
inside the loop will not statements inside the
execute loop will execute for at
least one time

Example of a do-while
loop:
Example of a while loop:
do {
while(condition)
statements to be
{statements to be executed;
executed:};
}while(condition or
expression);
13. Discuss the difference between prefix
and postfix?

prefix postfix

It simply means putting It simply means putting


the operator before the the operator after the
operand operand
It executes itself before It executes itself after ':

Associativity of prefix ++ Associativity of postfix


is right to left ++ is left to right

For more information, refer to the Difference


between prefix and postfix

14. What is the difference between new


and malloc()?
new malloc)

malloc is a function that


new is an operator
which performs an returns and accepts
operation values

new calls the malloc cannot call a


constructors constructor

new is faster than


malloc is slower than
malloc as it is an
new as it is a function
8. What is the difference between struct
and class?

Struct Class

Members of the class


Members of the struct
can be in private,
are always by default
protected, and public
public mode
modes.
Structures are of the Classes are of reference
value type. They only type. It holds areference
hold value in memory. of an object in memory.
The memory in
The memory in classes is
structures is stored as
stored as heaps.
stacks

For more information, refer to the Difference


between struct and class.

9. What is the difference between


reference and pointer?
Reference Pointer

The value of a reference The value of a pointer


cannot be reassigned can be reassigned
It can never hold a null
value as it needs an It can hold or point at a
11. What is the difference between an
array and a list?

Arrays Lists

Lists are classic


Array are contiguous
individual elements that
memory locations of
are linked or connected
homogenous data
to each other with the
types stored in a fixed
help of pointers and do
location or size.
not have a fixed size.
Arrays are static in Lists are dynamic in
nature. nature

Uses more memory as it


Uses less memory than has to store the value
linked lists. and the pointer memory
location

For more information, refer to Arrays Vs List


21. What is virtual inheritance?

Virtual inheritance is a technique that ensures only


one copy of a base class's member variables is
inherited by grandchild-derived classes. Or in
simple terms, virtual inheritance is used when we
are dealing with a situation of multiple
inheritances but want to prevent multiple
instances of the same class from appearing in the
inheritance hierarchy.

22. What is polymorphism in C++?


Polymorphism is known as many forms of the
same thing. In simple terms, we can say that
Polymorphism is the ability to display a member
function in multiple forms depending on the type
of object that calls them.

In other words, we can also say that a man can be


an employee to someone, a son of someone, a
father of someone, and a husband of someone;
this is how polymorphism can be projected in real
life.

There is 2type of polymorphism:

Compile Time Polymorphism


Function Overloading
Operator Overloading
2.. What are the different data types
present in C++?

DataTypes in C/ C+t+

Primary Derived User Defined

Integer Function Class

Character Array Structure

Boolean Pointer Union

Floating Point Reference Enum

Double Floating Point Typedef

Void

Wide Character

DG

Different types of data types in C++

For more information, refer to C++ data types

3. Define 'std'?

'std' is also known as Standard or it can be


interpreted as a namespace. The command "using
namespace std" informs the compiler to add
everything under the std namespace and inculcate
them in the global namespace. This all inculcation
3. Define 'std'?
'std' is also known as Standard or it can be

interpreted as a namespace. The command "using


namespace std" informs the compiler to add
everything under the std namespace and inculcate
them in the global namespace. This all inculcation
of global namespace benefits us to use "cout" and
"cin" without using "std::_operator".

For more information, refer to namespace and std.

4. What are references in C++?

When a variable is described as a reference it


becomes an alias of the already existing variable.
In simple terms, areferenced variable is another
named variable of an existing variable keeping in
mind that changes made in the reference variable
will be reflected in the already existing variable. A
reference variable is preceded with a '& symbol.

Syntax:

int GFG = 10;

1/ reference variable
int& ref = GFG;
16. What are classes and objects in C++?

A class is a user-defined data type where all the


member functions and data members are tailor
made according to demands and requirements in
addition to which these all can be accessed with
the help of an object. To declare a user-defined
data type we use a keyword class.

An object is an instance of a class and an entity


with value and state; In simple terms, it is used as
a catalyst or to represent a class member. It may
contain different parameters or none.

Note: A class is a blueprint that defines


functions which are used by an object.

For more information, refer to this What are


classes and objects

17.What is Function Overriding?


When a function of the same name, same
arguments or parameters, and same return type
already present/declared in the base class is used
in aderived class is known as Function Overriding.
17. What is Function Overriding?
When a function of the same name, same

arguments or parameters, and same return type


already present/declared in the base class is used
in a derived class is known as Function Overriding.
It is an example of Runtime Polymorphism or Late
Binding which means the overridden function will
be executed at the run time of the execution.

For more information, refer to Function Overriding


in C++

18. What are the various 0OPs concepts


in C++?

Classes: It is a user-defined datatype


Objects: It is an instance of a class
Abstraction: It is a technique of showing only
necessary details
Encapsulation: Wrapping of data in a single unit
"Inheritance: The capability of a class to derive
properties and characteristics from another
class

"Polymorphism: Polymorphism is known as many


forms of the same thing
1. What is C++? What are the advantages
of C++?

C++ is an object-oriented programming language


that was introduced to Overcome the jurisdictions
where C was lacking. By object-oriented we mean
that it works with the concept of polymorphism,
inheritance, abstraction, encapsulation, object, and
class.

Advantages of C++:

1. C++ is an 00Ps language that means the data is


considered as objects.
2. C++ is a multi-paradigm language; In simple
terms, it means that we can program the logiC,
structure, and procedure of the program.
3. Memory management is a key feature in C++ as
it enables dynamic memory allocation
4. It is a Mid-Level programming language which
meanS it can develop games, desktop
applications,drivers, and kernels
5. What do you mean by Call by Value and
Call by Reference?

In thisprogramming language to call a function we


have 2 methods: Call by Value and Call by
Reference

Callby Value Call by Reference

Acopyof a variable is A variable itself is passed


passed. fundamentally.
Calling a function by Calling a function by
sending the values by sending the address of
copying variables. the passed variable.

The changes made in The changes made in the


the function are never functions can be seen
reflected outside the outside the function on
function on the the passed function. In
variable. Inshort, the short, the original value is
original value is never altered in Callby
altered in Call by Value. reference.
Passed actual and Passed actual and formal

formal parameters are parameters are stored in


stored in different the same memory
memory locations. location. Therefore,
Therefore, making Call making Call by Reference
by Value a little a little more memory
memory insufficient efficient.
6. Define token inC++

Atoken is the smallest individual element of a


program that is understood bya compiler. Atoken
comprises the following:

1. Keywords - That contain a special meaning to


the compiler
2. ldentifiers - That hold a unique value/identity
3. Constants That never change their value
throughout the program
4. Strings That contains the homogenous
sequence of data
5. Special Symbols - They have sor
some special
meaning and cannot be used for another
purpose; eg: D0 },;*=#
6. Operators - Who perform operations on the
operand

You might also like