interview questions for C,OS,data structure

Sr.No.
Question
A.
C  Questions:
1
What does static variable mean?

2
What is a pointer?
Pointer is a variable which holds the address of another variable
3
What is a structure?

4
What are the differences between structures and arrays?
5
In header files whether functions are declared or defined?
decleration—header file
6
Difference between pass by reference and pass by value?
7
What are the differences between malloc() and calloc()?
8
What are macros? What are the advantages and disadvantages?
9
What is the use of typedef?
10
Can we specify variable field width in a scanf() format ?
11
What are register variables? What are the advantage of using register variables?
12
Describe about storage allocation and scope of global, extern, static, local and register variables?
13
Difference between arrays and linked list?
14
What are enumerations?
15
Where does global, static, local, register variables, free memory and C Program instructions get stored?
16
Where are the auto variables stored?
17
What is static identifier?
18
Out of fgets() and gets() which function is safe to use and why?
18
Difference between strdup and strcpy?
19
What does the error ‘Null Pointer Assignment’ mean and what causes this error?
20
What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?
21
What is a NULL Pointer? Whether it is same as an uninitialized pointer?
22
How will you declare an array of three function pointers where each function receives two ints and returns a float?
23
In a header file whether functions are declared or defined?
24
What is a far pointer? where we use it?
25
What is recursion?
26
What is the difference between Strings and Arrays?
27
What are the advantages of using pointers in a program?
28
What is difference between Structure and Unions?
29
Write down the equivalent pointer expression for referring the same element a[i][j][k][l]?
30
Differentiate between a for loop and a while loop? What are it uses?
31
What are the different storage classes in C?
32
Can a Structure contain a Pointer to itself?
33
What is near, far and huge pointers? How many bytes are occupied by them?
34
How would you obtain segment and offset addresses from a far address of a memory location?
35
Are the expressions arr and *arr same for an array of integers?
36
Does mentioning the array name gives the base address in all the contexts?
37
Explain one method to process an entire string as one unit?
38
What is the similarity between a Structure, Union and enumeration?
Structure occupies fixed width of memory space, while Union takes the required memory based on the values. Enum has a set of value to choose from and it can be part of either the Struct / Union or stand-alone
39
How can we check whether the contents of two structure variables are same or not?
There is no way to compare entire structure, we can only compare element by element.
example:
typedef struct{
int a;
int b;
} ravi_t;
main()
{
ravi_t r;
ravi_t s;
/* this is not allowed */
if(r==s) /* this is not allowed */;
/* where as we can compare element by element */
if(r.a == s.a);

40
How are Structure passing and returning implemented by the complier?

41
How can we read/write Structures from/to data files?
Fwrite(
42
Which expression always returns true and which expression always returns false?
expression if (a=0) always return false

expression if (a=1) always return true


expression if(1) always return true
expression if(0) always return fals
43
What is the difference between "malloc" and "calloc"?
44
Which expression always returns true and which expression always returns false?
45
Which are the best sorting algorithms to sort a linked list?
Merge
O(1)
46
What is a preprocessor and what will it do for a program?
47
What will be the output of the following program:
#include
main()
{
printf("%x",-1<<4);
}
48
What is a container class? What are the different types of container classes.
used to hold objects in memory or
external storage. A container class acts as a generic holder. A
container class has a predefined behavior and a well-known interface. A
container class is a supporting class whose purpose is to hide the
topology used for maintaining the list of objects in memory. When a
container class contains a group of mixed objects, the container is
called a heterogeneous container; when the container is holding a group
of objects that are all the same, the container is called a homogeneous
container
49
Name some pure object oriented languages.
50
What is a Null object?
51
How do you detect a loop in linked list?
52
How do we check whether a linked list is circular?
53
What is a Null object?
54
What is the difference between "malloc" and "calloc"
55
Which expression always returns true and which expression always returns false?
56
What is a preprocessor and what will it do for a program?
57
Which are the best sorting algorithms to sort a linked list?
58
What will be the output of the following program:
#include
main()
{
printf("%x",-1<<4);
}
59
What is a container class? What are the different types of container classes
60
Name some pure object oriented languages.
61
How would you use qsort() function to sort an array of structures?

62
How would you use bsearch() function to search a name stored in array of pointers to string?
63
How would you use the functions sin(), pow(), sqrt()?
64
Does there exist any other function which can be used to convert an integer or a float to a string?
char *itoa(int value, char *string, int radix);

DESCRIPTION
The itoa() function constructs a string representation of an integer.

PARAMETERS
value:
Is the integer to be converted to string representation.

string:
Points to the buffer that is to hold resulting string.
The resulting string may be as long as seventeen bytes.

radix:
Is the base of the number; must be in the range 2 - 36.

A portable solution exists. One can use sprintf():

char s[SOME_CONST];
int i = 10;
float f = 10.20;

sprintf ( s, “%d %f\n”, i, f );
65
How would you use qsort() function to sort the name stored in an array of pointers to string?
66
Write a program which uses functions like strcmp(), strcpy(), etc.
strcmp() is used to string comparision.strcpy() is used to string copy...
strcmp1("India");
strcmp2("India");
strcmp3("india");
if(strcmp1==strcmp2)
string is equal
else
if(strcmp1!=strcmp3)
string is not equal
strcpy
strcpy1("In");
strcpy2("dia");
strcpy3(strcpy1&&strcpy2)
output
 india

67
Write a program which uses command line arguments.
int main ( int argc, char *argv[] )

68
Write a program which employs Recursion?

69
Write a program to generate the Fibonacci Series?
#include<stdio.h>
 
int main()
{
   int n, first = 0, second = 1, next, c;
 
   printf("Enter the number of terms\n");
   scanf("%d",&n);
 
   printf("First %d terms of Fibonacci series are :-\n",n);
 
   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      printf("%d\n",next);
   }
 
   return 0;
}

70
Write a program to find the Factorial of a number.
#include "stdio.h"
fact(int n)
                { int factorial;
                  if(n==1)
                   return 1;
                  else
                   factorial=fact(n-1)*n;
                  return factorial;
                }
main()
                { int num,factorial;
                  printf("Enter any number : ");
                  scanf("%d",&num);
                  factorial=fact(num);
                  printf("The factorial of %d is %d ",num,factorial);
                  return 0;
                }
71
What are the advantages of using typedef in a program?
1. Readability. Just like naming your variables properly can show how you intend to use the variable, renaming the type can help show how you intend to use all variables of this type. It eliminates the possible bug of incorrect argument ordering (e.g. if a method signature has multiple boolean flags). 
2. Portability. On different systems you might want to have the same variable name (because you're using it the same way) to be of a different type. So you keep the typedef in a header file controlled by conditional compilation (for example) for maximal portability.
3. decreases complexity for declaring complex and repeated declarations like
typedef unsigned long int UINT64

72
Can you write a function similar to printf()?
#include <stdarg.h>
 
int summate(int n, ...)
{
    va_list ap;
    int i = 0;
 
    va_start(ap, n);
    for (; n; n--)
        i += va_arg(ap, int);
    va_end(ap);
    return i;
}

73
which can accept variable number of arguments?
#include <stdarg.h>

74
What is object file? How can you access object file?
An object file format is a computer file format used for the storage of object code and related data.

75
Can you dynamically allocate arrays in expanded memory?
int *ptr = malloc(10 * sizeof (int)); if (ptr == NULL) { /* Memory could not be allocated, the program should handle the error here as appropriate. */
realloc It is often useful to be able to grow or shrink a block of memory. This can be done using realloc which returns a pointer to a memory region of the specified size, which contains the same data as the old region pointed to by ptr (truncated to the minimum of the old and new sizes). If realloc is unable to resize the memory region in-place, it allocates new storage, copies the required data, and frees the old pointer. If this allocation fails, realloc maintains the original pointer unaltered, and returns the null pointer value. The newly allocated region of memory is uninitialized (its contents are not predictable). The function prototype is
void *realloc(void *pointer, size_t size);
76
Which header file should you include if you are to develop a function
77
How much maximum can you allocate in a single call to malloc()?
78
Which function should be used to free the memory allocated by calloc()?
Free()
79
When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
Automatically

80
How can you increase the size of a statically allocated array?
Simple answer is no, this cannot be done. Hence the name "static".
81
How can you increase the size of a dynamically allocated array?
int *ptr = malloc(10 * sizeof (int)); 
if (ptr == NULL) { /* Memory could not be allocated, the program should handle the error here as appropriate. */
realloc
It is often useful to be able to grow or shrink a block of memory. This can be done usingrealloc which returns a pointer to a memory region of the specified size, which contains the same data as the old region pointed to by ptr (truncated to the minimum of the old and new sizes). If realloc is unable to resize the memory region in-place, it allocates new storage, copies the required data, and frees the old pointer. If this allocation fails, realloc maintains the original pointer unaltered, and returns the null pointer value. The newly allocated region of memory is uninitialized (its contents are not predictable). The function prototype is
void *realloc(void *pointer, size_t size

82
How would you dynamically allocate a one-dimensional and two-dimensional array of integers?
One dimensional array

int *myarray = malloc(no_of_elements * sizeof(int));
//Access elements as myarray[i]
Two dimensional array
Method1
int **myarray = (int **)malloc(no_of_rows * sizeof(int *));
for(i = 0; i < no_of_rows; i++)
{
myarray[i] = malloc(no_of_columns * sizeof(int));
}
// Access elements as myarray[i][j]
Method2 (keep the array's contents contiguous)
int **myarray = (int **)malloc(no_of_rows * sizeof(int *));
myarray[0] = malloc(no_of_rows * no_of_columns * sizeof(int));
for(i = 1; i < no_of_rows; i++)
myarray[i] = myarray[0] + (i * no_of_columns);
// Access elements as myarray[i][j]
Method3
int *myarray = malloc(no_of_rows * no_of_columns * sizeof(int));
/ Access elements using myarray[i * no_of_columns + j].
Three dimensional array
#define MAXX 3
#define MAXY 4
#define MAXZ 5

main()
{
int ***p,i,j;
p=(int ***) malloc(MAXX * sizeof(int ***));

for(i=0;i < MAXX;i++)
{
p[i]=(int **)malloc(MAXY * sizeof(int *));
for(j=0;j < MAXY;j++)
p[i][j]=(int *)malloc(MAXZ * sizeof(int));
}

for(k=0;k < MAXZ;k++)
for(i=0;i < MAXX;i++)
for(j=0;j < MAXY;j++)
p[i][j][k]= < something >;

}

B.
DS questions :
1
What is data structure?
n computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently
2
A Linked list can grow and shrink in size dynamically at _runtime
3
What is the benefit of using a queue linked list?
Mainly, with linked lists you can delete any item anywhere and it's easy. You can also add an item into any position with ease too. With stacks and queues, you can only add/delete from the end
4
 What is linear hashing?
Linear hashing allows for the expansion of the hash table one slot at a time. The frequent single slot expansion can very effectively control the length of the collision chain. The cost of hash table expansion is spread out across each hash table insertion operation, as opposed to being incurred all at once.[2] Linear hashing is therefore well suited for interactive applications
5
List out the areas in which data structures are applied extensively?
1.Compiler Design,2.Operating System,3.Database Management System,4
6
What are the major data structures used in the following areas : RDBMS, Network data model and Hierarchical data model.
1. RDBMS Array (i.e. Array of structures)
2. Network data model Graph
3. Hierarchical data model Trees
7
If the depth of a tree is 3 levels, then what is the Size of the Tree?
2^3
8
Linear  form of access is used to add and remove nodes from a queue
9
What happens when you push a new node onto a stack?
10
 Define addressing and linear addressing functions? 
11
Name two desirable properties of hashing functions.
1.fast access
2.uniq hash function
12
What is the data structures used to perform recursion?
Stack. Because of its LIFO (Last In First Out) property it remembers its `caller' so knows whom to return when the function has to return.
13
Which is the simplest file structure? (Sequential, Indexed, Random)
seq
14
If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable of storing pointer to any type as it is a generic pointer type
15
Convert the expression ((A + B) * C - (D - E) ^ (F + G)) to equivalent Prefix and Postfix notations.
16
What is a spanning Tree?
A spanning tree of a connected graph G can also be defined as a maximal set of edges of G that contains no cycle, or as a minimal set of edges that connect all vertices
17
Minimum number of queues needed to implement the priority queue?
2
18
Whether Linked List is linear or Non-linear data structure?
non
18
Does the minimum spanning tree of a graph give the shortest distance between any 2 specified nodes?
No. The Minimal spanning tree assures that the total weight of the tree is kept at its minimum. But it doesn't mean that the distance between any two nodes involved in the minimum-spanning tree is minimum.
19
Sorting is not possible by using which of the following methods? (Insertion, Selection, Exchange, Deletion)
del
20
What is the data structures used to perform recursion?
satack
21
What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms?
22
What are the methods available in storing sequential files ?
·         Straight merging
·         Natural merging
·         Polyphase sort
·         Distribution of Initial runs


23
In RDBMS, what is the efficient data structure used in the internal storage representation?
B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes searching easier. This corresponds to the records that shall be stored in leaf nodes.

24
What are the types of Collision Resolution Techniques and the methods used in each of the type?
Open addressing (closed hashing),

                       The methods used include:

                        Overflow block

                            &

Closed addressing (open hashing)

                      The methods used include:

                            Linked list,

                           Binary tree..
25
Classify the Hashing Functions based on the various methods by which the key value is found.
1.    Direct method,:::::side sidu direct
2.    Subtraction method, h(x)-value
3.    Modulo-Division method,h(x)%value
4.    Digit-Extraction method,
5.    Mid-Square method,123
6.    Folding method,
7.    Pseudo-random method.

26
What is the bucket size, when the overlapping and collision occur at same time?
One. If there is only one entry possible in the bucket, when the collision occurs, there is no way to accommodate the colliding value. This results in the overlapping of values.
27
In an AVL tree, at what condition the balancing is to be done?
If the pivotal value (or the Height factor) is greater than 1 or less than 1.


if the balance factor of any node is other than 0 or 1 or -1 then balancing is done.


28
What is the type of the algorithm used in solving the 8 Queens problem?
backtracking
29
In tree construction which is the suitable efficient data structure? (Array, Linked list, Stack, Queue)
30
List out few of the applications that make use of Multilinked Structures?
31
List out few of the Application of tree data-structure?
32
 What is the most efficient way of finding a loop in linklist.
33
 Linked list C++ application is organized into three files.They are _____, ______ and _____
34
Difference between calloc and malloc in data structures?
35
How do you define a vector for a data structure?
36
 Value of the first linked list index is _______
37
A stack-linked list is a data structure that uses a ______ to create a stack
C.
OS Ques :
1
What is MUTEX ?

2
Explain Belady's Anomaly.
3
Explain the concept of Reentrancy. ?
4
Difference - Loading and Linking ?
5
What is Marshalling?
6
Define and explain COM?
COM (Component Object Model) technology in the Microsoft
Windows-family of Operating Systems enables software
components to communicate. COM is used by developers to
create re-usable software components, link components
together to build applications, and take advantage of
Windows services.
 
7
What are the different process states?
8
Explain the following file systems : NTFS, Macintosh(HPFS), FAT .
NTFS is a high-performance and self-healing file system proprietary to Windows XP 2000 NT, which supports file-level security, compression and auditing. It also supports large volumes and powerful storage solution such as RAID. 

FAT system <THE FAT FILE SYSTEMS. FAT32 FAT16 FAT12 >

The File Allocation Table (FAT) file system is a simple file system originally designed for small disks and simple folder structures. The FAT file system is named for its method of organization, the file allocation table, which resides at the beginning of the volume. To protect the volume, two copies of the table are kept, in case one becomes damaged. In addition, the file allocation tables and the root folder must be stored in a fixed location so that the files needed to start the system can be correctly located.
9
What is Semaphore?
10
Operating System Security.
11
Explain Scheduling.
12
What is INODE?
13
How does Windows NT supports Multitasking?

14
Explain the working of Virtual Memory.
16
What is Concurrency? Expain with example Deadlock and Starvation
Deadlock:

Two processes are said to be in deadlock situation if process A holding onto resources required for process B and where as B holding onto the resources required for process A.

Starvation:

This is mostly happens in time sharing systems in which the process which requires less time slot is waiting for the large process to finish and to release the resources, but the large process holding the resources for long time (almost for forever) and the process that requires small time slot goes on waiting. Such situation is starvation for small process.
17
What are your solution strategies for “Dining Philosophers Problem” ?
18
Explain Memory Partitioning, Paging, Segmentation.
PAGING: Paging memory allocation algorithms divide computer memory into small partitions, and allocates memory using a page as the smallest building block.

SEGMENTAION: Segmentation means that a part or parts of the memory will be sealed off from the currently running process, through the use of hardware registers. If the data that is about to be read or written to is outside the permitted address space of that process, a segmentation fault will result.


PAGING:-Paging is technique of allocating main memory to the process. In this the logical space of a program is divided into pages of equal size and main memory is divided into frames of size equal to page size. In this a page reside in any frame. In this pages are mapped to frames using Process Map Table(PMT).


Segmentation:- In segmentation logical address space of a job is divided into segments of may or may not be of equal size and main memory is also divide into segments..
18
Explain the Unix Kernel.
19
What are turnaround time and response time?
Turnaround time is the interval between the submission of a
job and its completion.

Response time is the interval between submission of a
request, and the first response to that request
20
What are the sub-components of I/O manager in Windows NT?
Network redirector/ Server
Cache manager.
File systems
Network driver
Device driver
21
What are DDks? Name an operating system that includes this feature.
22
What are the reasons for process suspension?
23
What is an idle thread?
24
What is mutant?
25
List out some reasons for process termination.
26
What is process spawning?
27
What is a drawback of MVT?
It does not have the features like 
ability to support multiple processors
virtual storage
source level debugging
28
What is SMP?
Symmetric multiprocessing (SMP) involves a multiprocessor computer hardware and software architecture where two or more identical processors are connected to a single shared main memory, have full access to all I/O devices, and are controlled by a single OS instance, and in which all processors are treated equally, with none being reserved for special purpose
29
When does the condition 'rendezvous' arise?
In message passing, it is the condition in which, both, the 
sender and receiver are blocked until the message is 
delivered
30
What is cycle stealing?
Cycle stealing is used to describe the "stealing" of a single CPU cycle, for example, to allow a DMA controller to perform a DMA operation. This is opposed to block operation where a DMA controller would request a bus, hold it for a complete transaction (typically 16-32 bytes but could last much longer) before releasing to a CPU

31
When is a system in safe state?
32
What is busy waiting?
The repeated execution of a loop of code while waiting for an event to occur is called busy-waiting. The CPU is not engaged in any real productive activity during this period, and the process does not progress toward completion


busy-wait is the state where a process spins in a while loop waiting for the lock/resource to become free. 
The processor is busy waiting for the resource to become available.
33
What is the Translation Lookaside Buffer (TLB)?
34
Explain the popular multiprocessor thread-scheduling strategies.




Comments