0% found this document useful (0 votes)
40 views2 pages

C Imp Questions

The document discusses differences between copy constructor and assignment operator, C structures and C++ structures, overloading and overriding, the need for virtual destructors, whether virtual constructors can exist, types of polymorphism, and types of storage classes. 1. The copy constructor copies a non-existing object, while the assignment operator assigns between two existing objects. The copy constructor creates a shallow copy and the assignment operator creates a deep copy. 2. In C++ structures, data members are private by default and functions can be members, while in C structures data members are public. 3. Overloading refers to the same name with different parameters within a class, while overriding replaces methods in a subclass with the

Uploaded by

Dhana Sekar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

C Imp Questions

The document discusses differences between copy constructor and assignment operator, C structures and C++ structures, overloading and overriding, the need for virtual destructors, whether virtual constructors can exist, types of polymorphism, and types of storage classes. 1. The copy constructor copies a non-existing object, while the assignment operator assigns between two existing objects. The copy constructor creates a shallow copy and the assignment operator creates a deep copy. 2. In C++ structures, data members are private by default and functions can be members, while in C structures data members are public. 3. Overloading refers to the same name with different parameters within a class, while overriding replaces methods in a subclass with the

Uploaded by

Dhana Sekar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

difference between copy constructor and assignment operator :


Copy constructor copies a existing object to a non existing object, which you are going to create.
Assignment operation can happen between two existing objects.
copy constructor creates shallow copy ,assignment operator creates deep copy.
Copy constructor is called every time a copy of an object is made. When you pass an object by
value, either into a function or as a function's return value, a temporary copy of that object is
made. Assignment operator is called whenever you assign to an object. Assignment operator
must check to see if the right-hand side of the assignment operator is the object itself. It executes
only the two sides are not equal.
2. Difference between "C structure" and "C++ structure":
The data members in C++ structure are private by default while in C they are public .2> The
structure variable initialization in C slso contains the struct keyword , while in C++ struct word is
not required . 3>In C++ structures , we can have functions as members .
3. difference between "overloading" and "overridding":
overloading refers to -same name but different definitions and parmeters.
Overriding refers to --'replacement' of methods.
Overriding - same method names with same arguments and same return types associated in a
class and its subclass.
Example:
class CSuper
{
null print ( string _name)
{
print "Hello" + _name;
}
};
class CDerived
{
null print ( string _name)
{
print "Hello" + _name + "from Derived";
}
};

Overloading - same method name with different arguments, may or may not be same return type
written in the same class itself.
Example:
class CClass
{
string print( int i);
string print(int i, char c);
};
4.Explain the need for "Virtual Destructor"
When classes are inherited we need to make the base class destructor virtual to make sure when
the object is destroyed all the derived class destructors also called. Otherwise the derived class
destructors are not called because the there is compile time binding of the destructor pointer to
the base class destructor.
5.Can we have "Virtual Constructors"?
In C++, Virtual is Used foe polymorphism, which is calling a Derived class function using the Base
class pointer. Since all the functions in the Public, protected are inherited we may have virtual
functions. BUT BUT Constructor of a class is never and ever extended by a derived, hence we
will never heed to have a Virtual constructor
6. What are the different types of polymorphism?
It is reacting differently for the same kind of message. For example, Consider Parrot,Penguin &
tiger .My message is "approach me quickly". Their different reactions: Parrot approaches me by "
flying" Penguin approaches me by "swimming" Tiger approaches me by "running" Here my
message is simply "pproach me quickly" But different things have been reacted differently. This is
called Polymorphism. As far as my knowledge is concerned there is only one type of
polymorphism and that is runtime polymorphism.

Polymorphism means one word having different meaning at


different instances.
There are two types.
1)Method overloading
2)Method overriding
There are two types of polymorphisms. They are
1) Compiletime Polymorphism
2) Runtime Polymorphism
In compiletime polymorphism we have Function Overloading and Operator Overloading.
In Runtime polymorphism we have Virtual Functions and Dynamic Binding.

What are the different types of Storage classes?


There are four types of storage classes.
1.Automatic: The scope is within the class that is like
local to its class
2.Extern: The scope of this is used within the class as
well as outside the class.so it is global
3.Regiter: These are mainly used for faster access of data.
4.Static: Once you declare the variable as static it will
remain constant throughout the program
There are four type of storage classes in C. These are used to store variables. These are Extern,
Static, Register and Auto. Auto is the default class assigned to any variable. eg. if we define int
x=10; then it means auto int x=10 register and static differ in only one grounds that register is
there in the cpu and static in the main memory.extern is global and can be accessed by any
program and anywhere.
What is Namespace?
Namespaces allow to group entities like classes, objects and functions under a name. This way
the global scope can be divided in "sub-scopes", each one with its own name.

The format of namespaces is:


namespace identifier
{
entities
}
namespace myNamespace
{
int a, b;
}

You might also like