You are on page 1of 4

Assignment 1

Q1 Answer any ten of the following questions briefly: [1.5x10]


i. What happens when you lose the address of a dynamically allocated block?
ii. Adding a floating point number to a pointer is not allowed, why?
iii. Pointer arithmetic makes sense only while working with arrays, comment.
iv. What is the difference between next and step commands of GDB?
v. What is the importance of the MAKE utility?
vi. Given a parameterized macro M and a function F what is the difference between M (a+1) and
F(a+1)?
vii. How would you use gcc to create a pre-compiled library of functions?
viii. State a problem situation when you would prefer using dynamic arrays (can grow in size) over
linked lists. Justify your choice.
ix. What is the difference between flexibility of choosing data-type received by using unions and
void* respectively?
x. State the responsibilities of realloc when a memory block of required size is available in heap,
but at a location different from the current storage.
xi. Spot the problem in the following code and state a way of rectifying it:
int * p, n, i;
scanf(%d, &n);
p= malloc (n*sizeof(int));
for (i=0; i<n; i++)
scanf(%d, p++)
xii. Spot the problem in the following code and state a way of rectifying it:
int* func()
{
int a[10];
// Given a function accept that can be used to input data values from user
accept(a, 10);
return a;
}
xiii. Given int *p, a[5][10];
Choose the logically correct assignment(s) from the following (justify your choice):
a. p=a;
b. p=a[1];
c. p= a[0][0];
d. p=&a[0][0];
Q2. Give short answers for any three of the following: [3x3]
i. Explain the difference between storage of union and structure variables. What are the applications
of the two ways of creating user defined datatypes?
ii. State the restrictions on void pointers. What is the justification behind these restrictions?
iii. An application requires to access records randomly on basis of record number. Which storage
scheme (binary / formatted text) will give more efficient results, why? How can you increase the
efficiency of random access of the less efficient approach?
iv. Draw and explain the memory map of a 2-Dimensional array created dynamically using a pointer
to an array. How many contiguous memory blocks are created on heap in this case?
v. How would you use conditional compilation to prevent multiple definitions of an identifier?
Explain the working of the mechanism used.

Q3. Write code snippets for any two of the following: [2x4]
i. Input and display data in a union token composed of mutually exclusive members operator (data
type float) and operand (data type char).
ii. Write a function to search for a data value in a linked list. The function must return a pointer to
the matching node on success and NULL on failure.
iii. Write a code snippet to copy all the records contained in a binary file into a dynamically created
array. The array should be allocated memory large enough to hold all the records in the file.
iv. Demonstrate the usage of function pointers in calling the library function bsort to sort an array of
struct Student on basis of rollno.
Q4. Write programs / functions for any two of the following: [6.5x2]
i. Records of employees of an organization are stored in a binary file. Write a function to modify
the phone number of an employee, given his employee ID. Also give the function call statement.
ii. Write functions to perform following operations on a linked list:
a. Delete the head node.
b. Add a node at end.
iii. Write a program to combine contents of multiple text files in a target file. The names of the files
must be accepted as command line parameters. Remember to include appropriate checks.
iv. Members of a society are to elect members of a coordination committee. The committee has five
posts. A member may choose not to vote at all. But if present, the member gives choices for all
the posts. You are required to:
a. Create a storage area dynamically large enough to hold all five choices of the members
who choose to vote.
b. Get users choices.
c. Display all the choices.
d. Free the memory.

Assignment 2

You might also like