Professional Documents
Culture Documents
Data Structure
Data Structure
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(); };
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.
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.