Thursday, February 23, 2012

array


1.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    char arr[7]="Network";
    printf("%s",arr);
   }

(A) Network
(B) N
(C) network
(D) Garbage value
(E) Compilation error
Explanation: **d  ,array size overflow....
2.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    char arr[11]="The African Queen";
    printf("%s",arr);
}
(A) The African Queen
(B) The
(C) Queen
(D) null
(E) Compilation error
Explanation: **d
3.
What will be output if you will execute following c code?
#include<stdio.h>
void main(){
    char arr[20]="MysticRiver";
    printf("%d",sizeof(arr));  
}
(A) 20
(B) 11
(C) 12
(D) 22
(E) 24
Explanation: **a

4.
What will be output if you will execute following c code?
#include<stdio.h>
void main(){
    int const SIZE=5;
    int expr;
    double value[SIZE]={2.0,4.0,6.0,8.0,10.0};
    expr=1|2;
    printf("%f",value[expr]);
}
(A) 2.000000
(B) 4.000000
(C) 6.000000
(D) 8.000000
(E) Compilation error
Explanation: **d ,as precedence of bitwise inclusive OR ( | ) is more than  assignment operator so                               1|2=3  expr=3;

5.
What will be output if you will execute following c code?

#include<stdio.h>
enum power{
    Dalai,
    Vladimir=3,
    Barack,
    Hillary
};
void main(){
    float leader[Dalai+Hillary]={1.f,2.f,3.f,4.f,5.f};
    enum power p=Barack;
    printf("%0.f",leader[p>>1+1]);
}
(A) 1
(B) 2
(C) 3
(D) 5
(E) Compilation error
Explanation: **b  , initial value of p is 4 right shift by 2 make p=1 leader[1]=2

6.
What will be output if you will execute following c code?

#include<stdio.h>
#define var 3
void main(){
    char *cricket[var+~0]={"clarke","kallis"};
    char *ptr=cricket[1+~0];
    printf("%c",*++ptr);
}
(A) k
(B) a
(C) l
(D) i
(E) Compilation error
Explanation: **c

7.
What will be output if you will execute following c code?

#include<stdio.h>
#define var 3
void main(){
    char data[2][3][2]={0,1,2,3,4,5,6,7,8,9,10,11};
    printf("%o",data[0][2][1]);
}
(A) 5
(B) 6
(C) 7
(D) 8
(E) Compilation error
Explanation: **a

8.
What will be output if you will execute following c code?

#include<stdio.h>
#define var 3
void main(){
    short num[3][2]={3,6,9,12,15,18};
    printf("%d   %d",*(num+1)[1],**(num+2));
}
(A) 12  15
(B) 12  12
(C) 15  15
(D) 15  12
(E) Compilation error
Explanation: **c

9.
What will be output if you will execute following c code?

#include<stdio.h>
#define var 3
void main(){
    char *ptr="cquestionbank";
    printf("%d",-3[ptr]);
}
(A) 100
(B) -100
(C) 101
(D) -101
(E) Compilation error
Explanation: **d

10.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    long  myarr[2][4]={0l,1l,2l,3l,4l,5l,6l,7l};
    printf("%ld\t",myarr[1][2]);
    printf("%ld%ld\t",*(myarr[1]+3),3[myarr[1]]);
    printf("%ld%ld%ld\t" ,*(*(myarr+1)+2),*(1[myarr]+2),3[1[myarr]]);
   }
(A) 6   66   777
(B) 6   77   667
(C) 5   66   777
(D) 7   77   666
(E) 6   67   667
Explanation: **b

11.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    int array[2][3]={5,10,15,20,25,30};
    int (*ptr)[2][3]=&array;
    printf("%d\t",***ptr);
    printf("%d\t",***(ptr+1));
    printf("%d\t",**(*ptr+1));
    printf("%d\t",*(*(*ptr+1)+2));
}
(A) 5   Garbage value   20   30
(B)   5    15    20    25
(C)  10   20    30    30
(D) 5    15    20    30
(E)  Compilation error

Explanation: **a


12.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    static int a=2,b=4,c=8;
    static int *arr1[2]={&a,&b};
    static int *arr2[2]={&b,&c};
    int* (*arr[2])[2]={&arr1,&arr2};
    printf("%d %d\t",*(*arr[0])[1],  *(*(**(arr+1)+1)));
}
(A) 2  4
(B) 4  2
(C) 4  8
(D) 8  4
(E) 8  2
Explanation: **c


13.
What will be output if you will execute following c code?

#include<stdio.h>
#include<math.h>
double myfun(double);
void main(){
    double(*array[3])(double);
    array[0]=exp;
    array[1]=sqrt;
    array[2]=myfun;
    printf("%.1f\t",(*array)((*array[2])((**(array+1))(4))));
}
double myfun(double d){
       d-=1;
       return d;
}
(A) 1.4
(B) 2.8
(C) 4.2
(D) 3.0
(E) 2.7
Explanation: **e


14.
What will be output if you will execute following c code?

#include<stdio.h>
#include<math.h>
typedef struct{
    char *name;
    double salary;
}job;
void main(){
    static job a={"TCS",15000.0};
    static job b={"IBM",25000.0};
    static job c={"Google",35000.0};
    int x=5;
    job * arr[3]={&a,&b,&c};
    printf("%s  %f\t",(3,x>>5-4)[*arr]);
}
double myfun(double d){
       d-=1;
       return d;
}
(A) Google 35000.000000
(B) TCS  15000.000000
(C) IBM  25000.000000
(D) null   15000.000000
(E) Google   null
Explanation: **a


15.
What will be output if you will execute following c code?

#include<stdio.h>
union group{
    char xarr[2][2];
    char yarr[4];
};
void main(){
    union group x={'A','B','C','D'};
    printf("%c",x.xarr[x.yarr[2]-67][x.yarr[3]-67]);
}
(A) A
(B) B
(C) C
(D) D
(E) null
Explanation: **b


16.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    int a=5,b=10,c=15;
    int *arr[3]={&a,&b,&c};
    printf("%d",*arr[*arr[1]-8]);
}
(A) 5
(B) 10
(C) 18
(D) Garbage value
(E)   Compilation error

Explanation: **e


17.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    int arr[][3]={{1,2},{3,4,5},{5}};
    printf("%d %d %d",sizeof(arr),arr[0][2],arr[1][2]);
}
(A)   6  0 4
(B) 6  1 5
(C) 18 0 5
(D) 18 1 5
(E) Compilation error
Explanation: **c


18.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    int xxx[10]={5};
    printf("%d %d",xxx[1],xxx[9]);
}
(A) 0  5
(B) 5  5
(C) 5  0
(D) 0  0
(E) Compilation error
Explanation: **d
19.
What will be output if you will execute following c code?

#include<stdio.h>
#define WWW -1
enum {cat,rat};
void main(){
    int Dhoni[]={2,'b',0x3,01001,'\x1d','\111',rat,WWW};
    int i;
    for(i=0;i<8;i++)
         printf(" %d",Dhoni[i]);
}
(A) 2 98 3 513 29 73 0 -1
(B) 2 98 3 513 30 73 1 -1
(C) 2 99 3 513 29 73 1 -1
(D) 2 98 3 513 29 73 1 -1
(E) Compilation error
Explanation: **d

20.
What will be output if you will execute following c code?

#include<stdio.h>
void main(){
    long double a;
    signed char b;
    int arr[sizeof(!a+b)];
    printf("%d",sizeof(arr))
}
(A) 8
(B) 9
(C) 1
(D) 4
(E) Compilation error
Explanation: **d

3 comments:

  1. give the explanation of que.7 why it evaluate 5 in octal.

    ReplyDelete
  2. Question 1 prints "Network" as the output when compiled in online compiler.

    ReplyDelete
  3. for 1st one how it becomes overflow

    ReplyDelete