:: Share Your Experience And Make People Share Like You ::

Tuesday 23 September 2014

cavium networks sample question

Q1) 
Define the enum ABC having attributes POSITIVE, NEGATIVE, and ZERO such that the 'fun()' function prints Postive for a positive number, Negative for a negative number and Zero for 0.

#include<stdio.h>
enum ABC
{
__________      //First Line
__________      //Second Line
__________      //Third Line
};
void fun(int num)
{
      if(num<=NEGATIVE)
           printf("Its a negative number\n");
      else
      {
           if(num>=POSITIVE)
                  printf("Its a positive number\n");
           else
                  printf("Zero\n");
      }
}
int main()
{
     int i;
     scanf("%d",&i);
     fun(i);
     return 0;
}
Answer: 
(a)
enum{
ZERO;
POSITIVE;
NEGATIVE=-1;
};
(b)
enum{
POSITIVE=1;
ZERO=0;
NEGATIVE=-1;
};

Q2)
#define Y 10
#define X 1-(Y)
int main()
{
    int val;
    val=200*X
    printf("Value of val is %d\n",val);
    return 0;
}
Answer: 190

Q3)
struct ABC
{
      int a;
      char b;
      void *c;
};
int main()
{
     struct ABC *obj=NULL;
     printf("%d: %d: %d: %d: %d\n",sizeof(obj->a),sizeof(obj->b),sizeof(obj->c),sizeof(obj),sizeof(struct ABC));
     return 0;
}

Answer:
4: 1: 4: 4: 12

Q4)
Design a data structure which can add 2 numbers in the range of 2127 to 2127-1

Answer:
struct my128int
{
     int a[4];
};

Q5) Using the data structure define above write a program which can add two numbers.

Q6) Using System Calls define printf function. Assume only one argument can be passed to this function.

Q7) Suppose you are having an instruction
sbn A,B,C
defined as
Memory[A]=Memory[A]-Memory[B]
if(Memory[A]<0)
    ProgramCounter=C.
Now, you are asked to write a code for moving the content of X to Y.

Answer:
sbn Y,Y,C     // setting Y=0
sbn T,T,C      // T is a temporary variable
sbn T,X,ProgramCounter+4      // T=-X
sbn T,X,ProgramCounter+4      // T=-2X
sbn Y,X,ProgramCounter+4      //  Y=-X
sbn Y,T,C                                  //  Y=X
sbn X,X,C                                  //  X=0

Q8)
#include<stdlib.h>
#include<stdio.h>
int main()
{
     int *p,*q,*r;
     p=malloc(sizeof(int));
     free(p);
     q=malloc(sizeof(int));
     free(q);
     r=malloc(sizeof(int));
     return 0;
}
Does p,q and r point to the same location?


Answer: Yes

Q9)
void fun(x)
{
    lock();
    IO_intensive();
    CPU_Intensive();
    unlock();
}
int main()
{
    fun(a);
    fun(b);
    fun(c);
    fun(d);
}
Choose the best answer:
(a) Uniporcessor System will give optimal performance for this situation.
(b) Dual Core will give optimal performance for this situation.
(c) Quad Core will give optimal performance for this situation.
(d) Multicore with altered code will give optimal performance for this situation..

Q10)
typedef struct tree* NODE
struct tree
{
    int info;
    struct tree *leftMostSibling,*rightSibling;
};
int fun(NODE root)
{
    int value=0;
    if(root)
    {
        value=1;
        value=value+fun(root->leftMostSibling);
        value=value+fun(root->rightSibling);
    }
    return(value);
}
What does function 'fun' returns?

Answer: Numbers of node in a tree.

Q11)
What is the output of the program given below?
#include<stdio.h>
void fun(int *p)
{
     p=malloc(sizeof(int));
}
int main()
{
     int *p=NULL;
     fun(p);
     if(p)
         printf("p is not null");
     else
         printf("null");
    return 0;
}
Answer: null

Q12)
int main()
{
    int a=0xabcdef;
    char *p;
    p=&a;
    printf("%x\n",*p);
    return 0;
}
What is the output?

Answer: Using the concept of big endian and little endian. It will be either '00' or 'ef'

source:
http://caviuminterviewexperience.blogspot.in/2014/08/cavium-networks-interview-experience.html