Compaq Interview Questions and Answers

Compaq Interview Questions and Answers
1)How do you do dynamic memory allocation in C applications? List advantages and disadvantages of dynamic memory allocation vs. static memory allocation.
Ans In C, malloc, calloc and realloc are used to allocate memory dynamically. In C++, new(), is usually used to allocate objects. Some advantages and disadvantages of dynamic memory allocation are:
• Memory is allocated on an as-needed basis. This helps remove the inefficiencies inherent to static memory allocation (when the amount of memory needed is not known at compile time and one has to make a guess).
• Dynamic memory allocation is slower than static memory allocation. This is because dynamic memory allocation happens in the heap area.
• Dynamic memory needs to be carefully deleted after use. They are created in non-contiguous area of memory segment.
• Dynamic memory allocation causes contention between threads, so it degrades performance when it happens in a thread.
• Memory fragmentation.
2.What are references in C++? Why do you need them when you have pointers?
3.Why paging is used ?
4.What leads to code-bloating in C++?
5.Which are the different network topologies ?
6.Write  a program to create delay code in c?
7.Why is analysis and testing phases very important ?
8.Write an algorithm for finding the greatest common divisor of two integers.?
9.What is the advantage of Ring network ?
Alogorithm questions asked
10.Write a program to reverse a singly linked list
11.Write a program to delete a node in double linked list
12.Write a program to insert a node in a sorted linked list

No comments: