ANNEXURE-I

Homework Title / No. : _____2_____________Course Code : __CSE2050_______ Course Instructor : __MR. RAJAN KAKKAR____Course Tutor (if applicable) : _________ Date of Allotment : ____13-09-2010________Date of submission : _____26-09-2010______ Student’s Roll No._____RC6801A07________Section No. : ______C6801______________ Declaration: I declare that this assignment is my individual work. I have not copied from any other student’s work or from any other source except where due acknowledgment is made explicitly in the text, nor has any part been written for me by another person. Student’s Signature : _____________

Evaluator’s comments: _____________________________________________________________________ Marks obtained : ___________ out of ______________________ Content of Homework should start from this page only:

The pointer help to store the address. the program may crash immediately. 2) If sufficient memory is not available during runtime for the storage of pointers. 3) The pointer has the address of the variable so it make the fast. It is also called pool allocation. 4) The pointer is necessary at the time of the run time memory. uses a free list of fixed-size blocks of memory . the program may crash. This works well for simple embedded systems . At the time of the same function the pointer help to recognize the variable. In this way the pointer is useful in the data structure. How the concept of pointers is useful in the implementation of data structures? Ans 1. The pointer is related to the data structure .) Function can return only one value. so at the time of fetching the data the pointer work.The main advantages of using pointers are: 1. The concept of pointers in the implementation of data structures is that if the link is broken at any node then the error is occurred. QUES 2: Elaborate the concept of “Fixed block storage allocation” and “Buddy system” in dynamic memory management.The data structure is the organization of the data that can be fetch easily at the line when it is needed. It tell the address of the data and we can receive data easily. Ans 2Fixed block storage allocation: It means the block that is assign fix size is called the fixed block storage allocation. 3) If the programmer is not useful and consistent with the use of pointers.) In the case of arrays we can decide the size of the array at runtime by allocating the necessary space.PART – A QUES 1: Write advantages and disadvantages of using pointer. 2. Disadvantages of pointers: 1) It is complex.

Buddy System : The system in which the memory is allocated in the big blocks and the size of that blocks is 2n then it is called the buddy system. The block is broken when the block that is allocated is large than it should be then the block is broken in two parts.Alloc(): It allocate the memory. It used to create a dynamic memory allocation in the C language.e no. In calloc we use 2 arguments i. It is the opposite of the static memory allocation. QUES 3: Differentiate between static memory allocation and dynamic memory allocation. e. and deallocation of dynamic memory used by the encode/decode functions. Memory management functions handle the allocation. reallocation. of elements .Calloc(): It allocate the data on the unused space. they have the particular size. The all blocks are in the link list. ptr= malloc(no. Dyanamic memory allocation: The dynamic memory is the memory that is given or assign to the variable on the run time. The block is compared its buddy only when the block is free. Realloc()-This function works in the same way as the C realloc function. It used to create memory allocation. A single copy of the data is retained. b. d. In this type of the memory allocation.size of int) c. Various memory management functions are: a. . They are combined if they are both free. the data is allocated logically. of arguments and size of it. It is the opposite of the dynamic memory allocation. Illustrate various memory management functions? Ans 3Static memory allocation : The static memory is the memory that is given or assign to the variable on the compile time. It reallocates an existing block of memory. Memory is assigned during compilation time.Malloc(): It return the void pointer to NULL.Free: it help to deallocate the memory.

The all info can be kept by the file.2. } We will use an array of character pointers to point to the strings declared as follows: char * nameptr[MAX]. There are many ways to manage the records: Array: In the C the array store the same kind of elements. Pointer: The pointer is the variable that can store the address of the another variable. PART – B QUES 5: Illustrate the use of array of pointers and pointers to an array? Ans 5Array of pointers: A pointer is a variable that stores the memory address of another variable. With the help of the array we can store the data of the same type. an array of memory addresses: #include <stdio. int *ptr1 = &int_array[0]. It manage the records.Ptr = realloc(ptr. . We store the information in the file. In other words. File: The file system is also helpful to manage record.new) QUES 4: Write different ways to manage records in memory? Ans 4.3}. So it's possible to have an array of pointers. It is also helpful for the storing the data.h> int main() { int int_array[3] = {1. int *ptr2 = &int_array[1].We have to manage the record so that we can get back when ever we want.

28. Far pointer is used to address data stored in data spaces . 30. The program has a dangling pointer f() { struct s *p = 0. The element is deleted that is point by the dangling pointer. 30. It point to addresses of the segment. There is no element on the location.. It means when any object is deleted then this kind of problem come. 31. It is used to access the far segment.. we realize that we can declare a pointer of the same data type as the array and initialize it with the array. p->next->val =. It includes segment number. 30. 31. 31. // p->next is dangling } g(struct s *p) { p->next = malloc(sizeof(struct s)). int *pNumbers = Number. // p is local g(p). int number[] = { 31. free_all_but_head(p). QUES 6: Give example to show the use of far pointer and dangling pointer problems? Ans 6Far pointer The pointer in which a segment selector is available is called far pointer. } . initialize(p). 30.. 31. h(p).Pointers to an array: Now that we know that the name of an array holds the address of the first member of the array. such pointers are used with farmalloc() and such. 31. to manage a heap separate from where all the rest of the data lives. Typically. Dangling pointer Dangling pointer means the pointer of invalid address. create_10_Node_List(p). 31 }. It make possible to point.

to find any element and give the location Main differences between the two are: 1) arrays are random access structures. for any no. It is not possible to binary searching the link list because in the linked list there is no confirmation of the beginning and ending point.e. Traverse means-go to the every node . 5th no. traversal and searching? Ans 7Linked list is the concept which is related with the pointer concept. otherwise if it is less than it. to be searched we'll check it first with the middle no. The pointer is used in the linked list. Coming to linked list.e. If it matches OK. no. If it is greater then we will check it with the middle no. of 5 & 10 i. equal to bounding no.e. .e. it is a way to store information without using arrays. in order to avoid it we use linked lists. 7 and so on. Array is the collection of same type of elements in continuous type. if no then illustrate the reason? Ans 8No. The search is carried till the no. 3 and so on. you have to specify its size. not found. is found or till middle no.QUES 7: Differentiate between linked list and arrays in terms of representations. With lists. we'll check the middle no. where you can access elements in random/indexed manner. in the array. of 1 & 5 i. Suppose we have 10 nos. we'll create a node containing information & the address of next node. i. i. Search means.e. whereas list is a sequential access structure. This makes such algorithms like heap sort or binary search to work much faster on arrays 2) arrays are static/fixed size whereas lists are dynamic size structures. i. The problem with array is we should know the maximum size in advance. QUES 8: Can we perform binary search in linked list. But in the array the pointer is not used because there is no need of the link in the array. It means that when creating an array (both on stack or heap). you just create an empty list and freely expand it. we can’t binary search in link list.

Sign up to vote on this title
UsefulNot useful