|
Data Structures Interview Questions and Answers
How memory is reserved using
a declaration statement ?
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.
How many parts are there in
a declaration statement?
There are two main parts, variable identifier and data type and the third type
is optional which is type qualifier like signed/unsigned.
Is Pointer a variable?
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.
What is Data Structure?
A data structure is a group of data elements grouped together under one name.
These data elements, known as members, can have different types and different
lengths. Some are used to store the data of same type and some are used to store
different types of data.
What is significance of
” * ” ?
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.
Why do we Use a
Multidimensional Array?
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.
Page Numbers :
1
2
3
4
5
6
7
Have a Question ?
post your questions here. It
will be answered as soon as possible.
Check
Structs Interview
Questions for more Structs Interview Questions with answers
Check
Object Oriented Interview
Questions for more Object Oriented Interview Questions with answers
|