Select chapter



functions (3.papers)
loops (1.papers)
arrays (2.papers)
structures (3.papers)
unions (1.papers)
pointers (7.papers)
null pointers (1.papers)
strings (2.papers)
misc c concepts (1.papers)
Data structures (5.papers)
linked lists (3.papers)
trees (1.papers)
basics (5.papers)
Hide

Sponsored Links


  

c data structures interview questions and answers

1
data structures in c:

What operation below function is doing?
And which data structure is this?

#define MAX_ELE 10 //assume maximum elements is 10
int cur; //points to current top element.

int fun (int ds[])
{  
    int val;
    if (cur == -1)
    {   
        val = -1;
    }
    else
    {   
        val = ds [cur];
        --cur;
    }
    return val;
}
  1. this function is trying to retrieve an existing element from the array ds[]. here ds is an array data structure.
  2. this function is trying to retrieve an existing element from top location of this data structure. So this is a stack. and operation here is pop operation.
  3. this function is trying to retrieve an existing element from starting location of this data structure. So this is a stack. and operation here is pop operation.
  4. this function is trying to retrieve an existing element from starting location of this data structure. So this is a queue. and operation here is deletion operation on queue.
Show Answer
Share Facebook gmail Twitter
2
assume below things

#define MAX_ELE 10 //assume maximum elements is 10
int cur; //points to current top element.

and Which of the below function are correct implementation of a stack pop() function?
  1. int fun (int ds[])
    {  
        int val;
        if (cur == -1)
        {   
            val = -1;
        }
        else
        {   
            val = ds [cur];
            --cur;
        }
        return val;
    }
  2. int fun (int ds[])
    {  
        int val;
        if (cur == MAX_ELE)
        {   
            val = -1;
        }
        else
        {   
            val = ds [cur];
            ++cur;
        }
        return val;
    }
  3. int fun (int ds[])
    {  
        int val;
        if (cur == 0)
        {   
            val = -1;
        }
        else
        {   
            val = ds [cur];
            --cur;
        }
        return val;
    }
  4. int fun (int ds[])
    {  
        int val;
        if (cur == 0)
        {   
            val = -1;
        }
        else
        {   
            val = ds [--cur];
        }
        return val;
    }
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
6
what is deque in c? (hint:double )
  1. removing element from the queue is called as deque.
  2. inserting an element into the queue is called as deque
  3. double ended queue, where we can insert and delete elements at both the ends.
  4. double ended queue, where we can insert at only end but we can delete from both the ends.
Show Answer
Share Facebook gmail Twitter
7
what is enqueue in c?
  1. inserting element into the queue is called as enqueue operation.
  2. queue where we can insert and delete at only one end is called as enqueue.
  3. queue where we can insert and delete at the same end is called as enqueue.
  4. queue where we can insert at only one end but can delete from any end.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
15
What is a bounded queue in c?
  1. Queue of fixed no of items.
  2. Queue of unlimited no of items.
  3. Queue which will not allow the value to be more than a bound value.
  4. Queue which will allow the value to be always more than a bound value.
Show Answer
Share Facebook gmail Twitter
16
linked list example in c:

What is below function fun() doing?
what is the operation, and what is this data structure?

 struct node
 {
 int data;
 struct node *link;
 }*head=NULL;


 void fun(int val)
 {
 struct node *temp = NULL;
 temp=(struct node *)malloc(sizeof(struct node));
 temp->data=val;
 temp->link=head;
 head=temp;
 }
  1. function fun() is trying to insert a new element into the singly linked list. operation here is insertion to the single linked list. data structure here is linked list.
  2. function fun() is trying to insert a new element at the end of previous element. this operation is a push operation on stack(as we insert new elements in stack at the end). this data structure is implementation of push operation of stack using a linked list.
  3. function fun() is trying to insert a new element at the end of previous element. this operation is a push operation on queue(as we insert new elements in queue at the end). this data structure is implementation of insert() operation of queue using a linked list.
  4. it can be either option 2 or 3.
Show Answer
Share Facebook gmail Twitter
17
Demo code for linked list in c:

What is below function disp() doing?
what is the operation, and what is this data structure?
assume that head is always pointing to the latest element added at the end.

 struct node
 {
 int data;
 struct node *link;
 }*head=NULL;


 void disp()
 {
  struct node *temp;
  if(head==NULL)
         printf("data structure is empty\n");
  else
  {
          temp=head;
          printf("retrieving... %d\n",temp->data);
          free(temp);
          head=head->link;
  }
 }
  1. disp is removing top(end) element from this data structure. so it is a pop() operation of a stack using linked list.
  2. disp is removing top element from this data structure. so it is a remove() operation of a queue using linked list.
  3. disp is removing first element from this data structure. so it is a pop() operation of a stack using linked list.
  4. disp is removing first(old) element from this data structure. so it is a remove() operation of a queue using linked list.
Show Answer
Share Facebook gmail Twitter
18
What is below function move() doing?
What is the name this famous program?
For which data structure, this is an example?

void move(int n,char *s,char *i,char *d)
{
 if(n>0)
 {
  move(n-1,s,d,i);
  printf("moving %d disk from %S to %s", n, s, d);
  move(n-1,i,s,d);
 }
}
  1. move is recursive function call to move 'n' number of rings from source 's' to destination 'd' towers respectively. this is famous towers of hanoi program. this is an example of stack architecture.
  2. move is recursive function call to move 'n' number of rings from source 's' to destination 'd' towers respectively. this is famous towers of hanoi program. this is an example of queue architecture.
  3. move is recursive function call to move 'n' number of rings from source 's' to destination 'i' towers respectively. this is famous towers of hanoi program. this is an example of stack architecture.
  4. move is recursive function call to move 'n' number of rings from source 's' to destination 'i' towers respectively. this is famous towers of hanoi program. this is an example of queue architecture.
Show Answer
Share Facebook gmail Twitter
19
in what order parameters passed to a function will be stored in the system's stack segment?

eg: If a function is taking 3 arguments int a, int b, int c . .like fun(int a, int b, int c){..} then when some body makes a call to this function with three parameters fun(x,y,z); then in what order these 3 variables will be stored in stack segment?
  1. stack will store in x,y,z order.. where z is the top most element inserted and it is the top most element to be popped out.
  2. stack will store in z,y,x order.. where x is the top most element inserted and it is the top most element to be popped out.
  3. it can be either option 1 or option2 but there is no guarantee.
  4. it really doesn't matter in which order it is going to store.
Show Answer
Share Facebook gmail Twitter
20
when a function calls other function in c language, then where does PC(program counter) will be stored? on top of the stack or below the local variables?
  1. first local variables will be stored in the stack of that function, and then on the top PC will be stored.
  2. first PC will be stored, and then the local variables of that function.
  3. it can be either option 1 or option2 but there is no guarantee.
  4. it really doesn't matter in which order it is going to store.
Show Answer
Share Facebook gmail Twitter
Read more papers :