Sunday, 17 June 2012

C language Sample Interview Questions




C Test


PAPER - 1




1) int prime[7]= {2, 3 ,5, 7, 11, 13};
  The size of the array ‘prime’ assuming ‘int’ variables to occupy 2 bytes is

a)     14
b)    12
c)     6
d)    None of these

2) a = 100;
    b = 5;
    c = a << b << 3;

Assuming the type of all variables to be ‘int’  the value stored in c is

a)     7
b)    25600
c)     5
d)    12800

3)

The output of the program :

#include <stdio.h>
int e=4;
struct x {int a; int b;};
struct x c = {3,4};
struct x d = {5,6};

  void main(){
  c.a = c.b + d.a;
  e = d.a + c.b;
  printf("%d\n",e);}

a)     9
b)    13
c)     10
d)    8


4)
The output of the program :

#include <stdio.h>
void main(){
  int a=1, b=2, c=3;
  a = b << c;
  printf("%d\n",a);}


a)     16
b)    32
c)     8
d)    2


Q 5 – Q7                        3

    5               7

                              1                0          2             9

6                                   4



          8

5) The counter-postfix notation is

          a) 4972683051
          b) 3794268501
          c) 1058624973
          d) 3510726894

6) The infix notation

          a) 3510726894
b) 1503862794
c) 3571029648
d) None of these

7) The corresponding binary search tree in infix notation is

          a) Binary search tree cannot be created as the elements are not sorted when  traversed in any order.
          b) 0123456789
          c) 1503862794
          d) None of these
         


8)Given the following declaration;
FILE *ifp;
Which of the following would not open the file “input.dat” for input in text mode?

a)     ifp = fopen (“input.dat”, “r”);
b)    ifp = fopen (“input.dat”, “r+”);
c)     ifp = fopen (“input.dat”,  “rb”);
d)    ifp = fopen (“input.dat”, “rt”);



Q9 – Q12
typedef union ut
{
    int I;
    float f;
    char s [20];
};

ut u, *pu, au [5];

(Assume that an int is '2 bytes', float is '4 bytes', char is '1 byte' and pointer is '4 bytes').


9) The size of ‘ut’ is
a)     20
b)    21
c)     Trying to find the size results in an error
d)    26

10) The size of  ‘u’ is
a)     21
b)    22
c)     20
d)    19

11) The size of ‘pu’ is
                   a)   20
                   b)   4
c)     26
d)    Cannot be decided as it is compiler dependent

12) The size of ‘au’ is
a)     80
b)    100
c)     130
d)    20


13)
The output of the program :

#include <stdio.h>

void main(){
  char c[ ] = "Hi_mom";
  char *cp = c;
  printf("%d\n",sizeof(cp));}

                   a) 6 
                   b) 5
                   c) 4
                   d) None of these as the ‘sizeof’ function flags an error


14) p is a 15-element array of pointers to functions; each function accepts an argument which is a pointer to a float and returns a pointer to a double. The declaration used is

          a)  double (**p[15]) (float []);
          b) double *(*p[15])(float *a);
          c) double *( (*p)[15]) *(float a);
          d) double (*p[]) *(float *a);

   
15)           Assume the size of int to be 2 bytes and the program is run on a 486 machine

register int a = 10;

The size of a

a)     is 2 as int is assumed to occupy 2 bytes
b)    Error ! As it is illegal to find the size of a register variable
c)     is 4 as registers of 486 are 32bit in length
d)    Compiler dependent



PAPER – 2


Assume char occupies 1 byte, int 2 bytes, float 4 bytes and double 8 bytes unless explicitly stated.

1) What is the number of bytes occupies  by  the array Arr declared as
double Arr [20] [5] [6];

a)     3040
b)    4800
c)     2400
d)    1200

2) Which one of the following with respect to the following declarations is true :
char strl [5] = "ABCD";
char *str2 = "ABCD";

a)     size of str1 = size of str2
b)    str1[5] = ‘\0’;
c)     *(str2+4) = ‘\0’;
d)    All are false


3) The output of the program :

#include <stdio.h>

void main(){

  int a=1, b=2, c=3, d=4;

  char ca[80];

  a= sprintf(ca,"%1d %1d %1d\n",b,c,d);

  printf("%d\n",a);}

a)     2 3 4
1

b)    2 3 4
6

c)     6
d)    None of the above



4) The output of the program :

#include <stdio.h>

void main(){

  int a=1, b=2, c=3;

  a = b << c;

  printf("%d\n",a);}

a)     2
b)    8
c)     4
d)    16


5) The output of the program :

#include <stdio.h>

void main(){

  int a=1, b=5, c=3;

  a = b ^ c;

  printf("%d\n",a);}

a)     5
b)    7
c)     1
d)    None of the above


6)

float a = 3.56;

void main()
{
  float b;

  b = a % 3;
  printf (“%f”,b);
}

a)     0.56
b)    Results in a compiler error
c)     Results in a  linker error
d)    Depends on the compiler


7)    Sparse matrix is

a)    A  representation  of a matrix containing more zero elements
b )   A matrix wherein the number of  non-zero elements is very less
c)     A representation of a matrix containing only zero elements
d)    A singular matrix


8)   The sorting technique with the best efficiency when the no. of elements is large and the no. of digits in each element is quite less is
a)     Quick sort
b)    Merge sort
c)     Bubble sort
d)    Radix sort

9) The output of the program is

#include <stdio.h>
#include <string.h>

void main(){
  char c[] = "Hi folks";
  char d[] = "Hi folks";
  printf("%d\n",strcmp(c,d));}

a)     0
b)    Some non-zero value
c)     Declaration error
d)    None of the above



10)
 The output of the program :

#include <stdio.h>
int play(int x, int y){
  int a;
    if (y == 0) return 1;

    if (y % 2 == 0) return (play (x,y/2)*play(x,y/2));

    return (x*play(x,y/2)*play(x,y/2));
  }

  void main(){
    int a, b=8;
      a = play(3, b);
      printf("%d\n",a);}

a)     Goes to an infinite loop
b)    81
c)     2187
d)    6561



11)           The value of  ‘i’  when the loop terminates

int i,j;

for (i = 0,j = 0; i <= 10, j < 5; i++, j+=2);

a)     3
b)    11
c)     4
d)    10

12)
The output of the following program :

#include <stdio.h>
void main(void){
  int a=2;
  switch (a){

    case 0:a=a+2;

    case 1:a=a+4;

    case 2:a=a+8;

    case 3: a=a+6;

    default: a=a+32;}

  printf("%d\n",a);}

          a)  10
          b) Error because of absence of ‘break’ statement at the end of case structure
c) 48
          d)  14



13)           Assuming ‘i’ to be an integer with the value 10 the output of the following program statement

printf (“ %d %d %d”, ++i, i++, i);

is

a)     12 10 10
b)    11 11 12
c)     10 12 12
d)    11 12 12

14)           ‘Function xxxx should have a prototype’  errors are produced during
a)     Run-time
b)    Compile Time
c)     Link Time
d)    While preprocessing

15)           The output of the program


void main()
{
  char  str[5] = “abc”;

 printf (“%s”,&0[str]);
}

a)     abc
b)    Error
c)     Unpredicatable output
d)    bc


Answers – Paper 1


1)    a
2)    b
3)    a
4)    a
5)    b
6)    b
7)    b
8)    c
9)    a
10)           c
11)           b
12)           b
13)           c
14)           b
15)           a

Paper – 2


1)    b
2)    c
3)    c
4)    d
5)    d
6)    b
7)    a
8)    d
9)    a
10) d
11) a
12) c
13) a
14)c
15) a

0 comments:

Post a Comment