• +91 9723535972
  • info@interviewmaterial.com

Data structure Interview Questions and Answers

Data structure Interview Questions and Answers

Question - 21 : - What is placement new?

Answer - 21 : - When you want to call a constructor directly, you use the placement new. Sometimes you have some raw memory that’s already been allocated, and you need to construct an object in the memory you have. Operator new’s special version placement new allows you to do it. class Widget { public : Widget(int widgetsize); … Widget* Construct_widget_int_buffer(void *buffer,int widgetsize) { return new(buffer) Widget(widgetsize); } }; This function returns a pointer to a Widget object that’s constructed within the buffer passed to the function. Such a function might be useful for applications using shared memory or memory-mapped I/O, because objects in such applications must be placed at specific addresses or in memory allocated by special routines.  

Question - 22 : - ARRAY and STACK?

Answer - 22 : - STACK follows LIFO. Thus the item that is first entered would be the last removed. In array the items can be entered or removed in any order. Basically each member access is done using index. No strict order is to be followed here to remove a particular element.

Question - 23 : - What is the difference between NULL AND VOID pointer?

Answer - 23 : - NULL can be value for pointer type variables. VOID is a type identifier which has not size. NULL and void are not same. Example: void* ptr = NULL;

Question - 24 : - What is precision?

Answer - 24 : - Precision refers the accuracy of the decimal portion of a value. Precision is the number of digits allowed after the decimal point.

Question - 25 : - What is impact of signed numbers on the memory?

Answer - 25 : - Sign of the number is the first bit of the storage allocated for that number. So you get one bit less for storing the number. For example if you are storing an 8-bit number, without sign, the range is 0-255. If you decide to store sign you get 7 bits for the number plus one bit for the sign. So the range is -128 to +127.

Question - 26 : - How memory is reserved using a declaration statement ?

Answer - 26 : - Memory is reserved using data type in the variable declaration. A programming language implementation has predefined sizes for its data types. For example, in C# the declaration int i; will reserve 32 bits for variable i. A pointer declaration reserves memory for the address or the pointer variable, but not for the data that it will point to. The memory for the data pointed by a pointer has to be allocated at runtime. The memory reserved by the compiler for simple variables and for storing pointer address is allocated on the stack, while the memory allocated for pointer referenced data at runtime is allocated on the heap.

Question - 27 : - How many parts are there in a declaration statement?

Answer - 27 : - There are two main parts, variable identifier and data type and the third type is optional which is type qualifier like signed/unsigned.

Question - 28 : - Is Pointer a variable?

Answer - 28 : - Yes, a pointer is a variable and can be used as an element of a structure and as an attribute of a class in some programming languages such as C++, but not Java. However, the contents of a pointer is a memory address of another location of memory, which is usually the memory address of another variable, element of a structure, or attribute of a class.

Question - 29 : - What is significance of  ” * ” ?

Answer - 29 : - The symbol “*” tells the computer that you are declaring a pointer. Actually it depends on context. In a statement like int *ptr; the ‘*’ tells that you are declaring a pointer. In a statement like int i = *ptr; it tells that you want to assign value pointed to by ptr to variable i. The symbol “*” is also called as Indirection Operator/ Dereferencing Operator.

Question - 30 : - Why do we Use a Multidimensional Array?

Answer - 30 : - A multidimensional array can be useful to organize subgroups of data within an array. In addition to organizing data stored in elements of an array, a multidimensional array can store memory addresses of data in a pointer array and an array of pointers. Multidimensional arrays are used to store information in a matrix form. e.g. a railway timetable, schedule cannot be stored as a single dimensional array. One can use a 3-D array for storing height, width and length of each room on each floor of a building.  


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners