InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What is delete operator in C++? |
|
Answer» The delete operator in C++ releases dynamically allocated memory. |
|
| 2. |
What is a delete operator in C++? |
|
Answer» The delete operator in C++ releases dynamically allocated memory. |
|
| 3. |
What is delete operator in C++? Give an example. |
|
Answer» The delete operator in C++ is used for releasing memory space when the object is no longer needed. General syntax of delete operator in C++: delete pointer_variable; |
|
| 4. |
What is new operator in C++? Give an example. |
|
Answer» The new operator in C++ is used for dynamic storage allocation. This operator can be used to create an object of any type. General syntax of the new operator in C++: The general syntax of a new operator in C++ is as follows: For example: int *a=new int; |
|
| 5. |
Illustrate the use of “self-referential structures” with the help of an example. |
|
Answer» A self-referential structure is used to create data structures like linked lists, stacks, etc. Following is an example of this kind of structure where pointer variable *next is of datatype ‘node’ which is the structure type itself: |
|
| 6. |
What are the advantages of a pointer? |
|
Answer» The advantages of the pointer are:
|
|
| 7. |
How dynamic memory allocation is different from static memory allocation? |
|
Answer» Allocation of memory for data is done at the time of execution (run time) is known as dynamic memory allocation. Whereas allocation of memory is for data is done during compilation in fixed size is called static memory allocation. |
|
| 8. |
Explain with example by passing the pointers. |
|
Answer» #include <iostream> // function definition to swap the values, void swap(int *x, int *y) The output of the above program is: In the above program, swap() function is declared with two arguments of type integer pointers. During the function call memory address of variable, ‘a’ and variable ‘b’ is passed as actual arguments, and formal arguments are pointer ‘x’ and pointer Y takes the address of ‘a’ and ‘b’ variables respectively. In the body of the swap function, the pointer operator is used to access the value at the location. Here the memory location of ‘a’ and ‘b’ are accessed by the pointers V and Y and produces the output as shown above. |
|
| 9. |
What is the relationship between object and pointers? Give an example. |
|
Answer» The pointers pointing to objects are referred to as object pointers. There is a relationship between pointers and objects. Using pointers all the members of the class can be accessed. The following example shows various operations that can be performed on the members of the class through a pointer to objects. Declaration : class name *object_pointer, object; { int empno; public: void readdata(); emp obj, *ptr; |
|
| 10. |
Explain with example by passing the reference. |
|
Answer» #include <iostream> swap(a, b); The output of the above program is: In C++, reference variables are possible and works like alias to original memory locations. In the above program, the function void swap(int& x, int& y); is declared with two arguments with x and y as reference variables. During the function call swap() takes two arguments (formal arguments) ‘x’ and ‘y’ which are reference variables to variables of actual arguments ‘a’ and ‘b’ respectively. The interchange of value takes place between x and y in the body of swap() function. Here, variable ‘x’ and ‘y’ are used to manipulate the data values from the location ‘a’ and ‘b’ directly. |
|