Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

DATA STRUCTURE Q1. Define Data Structure? Ans.

A data structure is a specialized format for organizing and storing data. General data
structure types include the array, the file, the record, the table, the tree, and so on. Any data structure is designed to organize data to suit a specific purpose so that it can be accessed and worked with in appropriate ways. In computer programming, a data structure may be selected or designed to store data for the purpose of working on it with various algorithms.

Q2. Mention types of data structure? Ans. An ADT is a collection of data and associated operations for
manipulating that data ADTs support abstraction, encapsulation, and information hiding They provide equal attention to data and operations Common examples of ADTs: Built-in types: boolean, integer, real, array User-defined types: stack, queue, tree, list boolean Values: true and false Operations: and, or, not, nand, etc. integer Values: Whole numbers between MIN and MAX values Operations: add, subtract, multiply, divide, etc. arrays Values: Homogeneous elements, i.e., array ofX. . .

Operations: initialize, store, retrieve, copy, etc. Q3. What is constructor? Ans. A constructor is a member function with the same name as its class. For example:
class X { public: X(); };

// constructor for class X

Constructors are used to create, and can initialize, objects of their class type. You cannot declare a constructor as virtual or static, nor can you declare a constructor as const, volatile, orconst volatile. You do not specify a return type for a constructor. A return statement in the body of a constructor cannot have a return value.

Q4.What is Resursion? Ans. In computer programming, a recursion (noun, pronounced ree-KUHR-zhion) is


programming that is recursive (adjective), and recursive has two related meanings: 1) A recursive procedure or routine is one that has the ability to call itself. This usually means that it has the capability to save the condition it was in or the particular process it is serving when it calls itself (otherwise, any variable values that have been developed in executing the code are overlaid by the next iteration or go-through). Typically, this is done by saving values in registers or data area stacks before calling itself or at the beginning of the sequence where it has just been reentered. 2) A recursive expression is a function, algorithm, or sequence of instructions (typically, an IF, THEN, ELSE sequence) that loops back to the beginning of itself until it detects that some condition has been satisfied. Here is a simple example (using a made-up computer source language):

CODELINE1 N=0; CODELINE2 IF N=<10 THEN DO WRITE LETTER; CODELINE3 ELSE GOTO CODELINE6; CODELINE4 N=N+1; CODELINE5 GOTO CODELINE2; CODELINE6 ...some other instruction

Q5. Definition of dereference Ans. Definition: In C and C++, dereference applies to a pointer and means to access
the variableor memory location that the pointer points to. int a=9; int * ptra = &a; *ptra= 10; printf("Value of a is %i",a) ;

Q6. What is meant by Dereferencing Pointer? Ans. The dereference operation starts at the pointer and follows its arrow over to access its pointee. The goal may be
to look at the pointee state or to change the pointee state. The dereference operation on a pointer only works if the pointer has a pointee -- the pointee must be allocated and the pointer must be set to point to it. The most common error in pointer code is forgetting to set up the pointee. The most common runtime crash because of that error in the code is a failed dereference operation. In Java the incorrect dereference will be flagged politely by the runtime system. In compiled languages such as C, C++, and Pascal, the incorrect dereference will sometimes crash, and other times corrupt memory in some subtle, random way. Pointer bugs in compiled languages can be difficult to track down for this reason.

You might also like