Technical Interview Questions and Answers :: C++
void operator delete(void *p)
/*free memory pointed to by p. the destructor is called automatically.*/
The delete function receives a pointer to the region of memory to be freed. It then releases the previously allocated memory back to the system. When an object is deleted, its destructor is automatically called.
void *operator new (size_t size)
/*performs the allocation operation.
The constructor is called automatically.
returns the pointer to memory*/
size_t - It is a defined type capable of containing the largest single piece of memory that can be allocated.
Size - It contains the number of bytes needed to hold the object being allocated.
When we allocate an object using new, the objectâ€™s constructor is automatically called.
â€¢ It prevents us from having to provide an overloaded constructor that takes no parameters.
â€¢ It is convenient by providing the default common initial values than specifying them each time an object is declared.
â€¢ We can use default arguments to add new parameters to the existing functions.
â€¢ Default arguments can be used to combine similar functions into one.
Functions are said to be overloaded when they have the same name with the different number and the type of the arguments. Two functions differing only in their return types cannot be overloaded.
Two or more functions can share the same name that perform a variety of different tasks as long as their parameter declarations are different. The functions that share the same name are said to be overloaded, and the process is referred to as function overloading.
Class objects can be initialized dynamically too. That is, the initial value of an object may; be provided during run time.
We can provide various initialization formats, using overloaded constructor. This provides the flexibility of using different format of data at run time depending upon the situation.
1. The constructor that accepts no parameter is called is a default constructor.
2.it is used in class by
A :: A( )
Default argument constructor:
1. The default argument constructor can be called with either one argument or no arguments.
2. It is used in class by
A:: A(int =0)
To pass values as arguments to the constructor function when an object is declared.
By calling the constructor implicitly
Integer int1 (0,100);
This method is called as shorthand method, is used very often as it is shorter, looks better and is easy to implement.
To pass values as arguments to the constructor function when an object is declared. This done in two ways.
1. By calling the constructor explicitly.
2. By calling the constructor implicitly.
You can check latest and updated C++ Job Interview Questions and Answers on this page. You can filter the question set by the company's name. Looking for the right answer? Don't worry! You can click on view answer section and check the answer with the explanation. You can discuss the answer in the forum with other users easily. Login with Facebook and save the answer To Reading List right now!
Our site contains top IT companies placement paper and mock test to help the freshers and experienced candidate to get hands on experience on the pattern and type of questions. We have curated all the C++ technical interview questions and answers from previous candidates.