Short Answer type Questions of C/C++ Language

1. What are objects? How are they created?
Objects are basic run-time entities in an object-oriented programming system. The class variables are known as objects. Objects are created by using the syntax: 
a. Object declaration after the class declaration:
class_name object;
b. Object declaration during the class declaration:

class class_name
{
data member_1;
data member_n;
member function_1;
member function_n;
}
object;

2. Describe the importance of destructor.
A destructor destroys the objects that have been created by a constructor upon exit from the program or block to release memory space for future use. It is a member function whose name is the same as the class name but is preceded by a tilde.
Syntax:
~class_name()
}

3. What do you mean by friend functions?
C++ allows some common functions to be made friendly with any number of classes, thereby allowing the function to have access to the private data of thse classes. Such a function need not be a member of any of these classes. Such common functions are called friend functions.

4. What are member functions?
Functions that are declared within the class definition are referred as member function.

5. Define dynamic binding.
Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run-time.

6. Write any properties of constructor.
a. Constructors should be declared in the public section.
b. They are invoked automatically when the objects are created.
c. They do not have return types
d. They cannot be inherited

7. List any Operators that cannot be overloaded.
a. Class member access operator (. , .*)
b. Scope resolution operator (::)
c. Size operator ( sizeof )
d. Conditional operator (?:)

8. What is a Destructor? 
A destructor is used to destroy the objects that have been created by a constructor. It is a special member function whose name is same as the class and is preceded by a tilde ‘~’symbol. When an object goes out from object creation, automatically destructor will be executed.

9. What is the Need for initialization of object using Constructor? 

If we fails to create a constructor for a class, then the compiler will create a constructor by default in the name of class name without having any arguments at the time of compilation and provides the initial values to its data members. So we have to initialize the objects using constructor.

10. What is a Copy Constructor.
A copy constructor is used to declare and initialize an object from another object. It takes a reference to an object of the same class as an argument.


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

1 comments:


  1. The need for initialization of an object using a constructor is to set the initial state of the object. This includes assigning values to the object's properties and initializing its methods.

    Without a constructor, the object would be created in an undefined state, which could lead to errors. For example, if an object has a property that is supposed to be an integer, but it is not initialized, the property would be assigned a default value of null or 0, depending on the programming language. This could lead to unexpected behavior if the property is later used in a calculation.

    ReplyDelete