Set - 3

Question 1 :

How memory is reserved using a declaration statement ?

Answer :

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 2 :

How many parts are there in a declaration statement?

Answer :

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

Question 3 :

Is Pointer a variable?

Answer :

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 4 :

What is Data Structure?

Answer :

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.

Question 5 :

What is significance of  " * " ?

Answer :

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 6 :

Why do we Use a Multidimensional Array?

Answer :

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.

Question 7 :

How do you assign an address to an element of a pointer array ?

Answer :

We can assign a memory address to an element of a pointer array by using the address operator, which is the ampersand (&), in an assignment statement such as ptemployee[0] = &projects[2];

Question 8 :

Run Time Memory Allocation is known as ?

Answer :

Allocating memory at runtime is called a dynamically allocating memory. In this, you dynamically allocate memory by using the new operator when declaring the array, for example : int grades[] = new int[10];

Question 9 :

What method is used to place a value onto the top of a stack?

Answer :

push() method, Push is the direction that data is being added to the stack. push() member method places a value onto the top of a stack.

Question 10 :

What method removes the value from the top of a stack?

Answer :

The pop() member method removes the value from the top of a stack, which is then returned by the pop() member method to the statement that calls the pop() member method.

Question 11 :

What does isEmpty() member method determines?

Answer :

isEmpty() checks if the stack has at least one element. This method is called by Pop() before retrieving and returning the top element.

Question 12 :

What is a queue ?

Answer :

A Queue is a sequential organization of data. A queue is a first in first out type of data structure. An element is inserted at the last position and an element is always taken out from the first position.

Question 13 :

What is the relationship between a queue and its underlying array?

Answer :

Data stored in a queue is actually stored in an array. Two indexes, front and end will be used to identify the start and end of the queue.

When an element is removed front will be incremented by 1. In case it reaches past the last index available it will be reset to 0. Then it will be checked with end. If it is greater than end queue is empty.

When an element is added end will be incremented by 1. In case it reaches past the last index available it will be reset to 0. After incrementing it will be checked with front. If they are equal queue is full.

Question 14 :

Which process places data at the back of the queue?

Answer :

Enqueue is the process that places data at the back of the queue.

Question 15 :

Why is the isEmpty() member method called?

Answer :

The isEmpty() member method is called within the dequeue process to determine if there is an item in the queue to be removed i.e. isEmpty() is called to decide whether the queue has at least one element. This method is called by the dequeue() method before returning the front element.