Upload
rajendrashah8
View
616
Download
0
Embed Size (px)
Citation preview
8/2/2019 Final Expert Level c Aptitude Round
1/23
CORRECT
ANSWER
1 | P a g e
1) What will be the output of the following program?void fun(char * msg,);
int main(){fun(Nothing specific\n,1,4,7,11,0);
}void fun(char * msg,){
int tot=0;
va_list ptr;int num;va_start(ptr,msg);
num=va_arg(ptr,int);num=va_arg(ptr,int);printf(\n%d,num);
}
A) 1B) 2C) Runtime ErrorD) 4
2) What is the correct statement about the given piece of code?void varfun(int n,);
int main(){
varfun(3,7.5,-11.4,0.33);}
void varfun(int n,){float *ptr;int num;
va_start(ptr,n);num=va_arg(ptr,int);
printf(\n%d,num);}
A) The first argument will be converted to float.B) The type of ptr is float* which will be converted to va_list *C) Variable number of arguments must declare the ptr of type va_list.D) The program successfully compiles and will display 3.000000.3) Which of the given options is correct about the following program
void display(char * s,);
int fun1();
int fun2();
int main(){
int(*p1)();int (*p2)();
8/2/2019 Final Expert Level c Aptitude Round
2/23
CORRECT
ANSWER
2 | P a g e
p1=fun1;p2=fun2;
display(Bye,p1,p2);
return 0;}
void display(char * s,){
int (*pp1)();int (*pp2)();
va_list ptr;
va_start(ptr,s);pp1=va_arg(ptr,int(*)());
(*pp1)();pp2=va_arg(ptr,int(*)());
(*pp2)();
}
int fun1(){
printf(\nHello);return 0;
}
int fun2(){printf( Hi);
return 0;
}
A) va_arg cannot extract the function pointer from the variable argument list in themanner tried above.
B) Program runs successfully to display Hello HiC)
The address of a function cannot be passed to the function with variable number ofarguments.
D) Function with fixed arguments cannot be called from function with variablearguments.
4) Which of the following is the correct output for the program given below?int main(){
printf(%x,-1
8/2/2019 Final Expert Level c Aptitude Round
3/23
CORRECT
ANSWER
3 | P a g e
for(i=1;i
8/2/2019 Final Expert Level c Aptitude Round
4/23
CORRECT
ANSWER
4 | P a g e
}
A) 2 BytesB) 48 bytesC) 12 bytesD) 24 bytes9) What is the correct statement about the following piece of code?
int main(){
int ***p,i,j,k;p=(int***)malloc(sizeof(int**)*4);
for(i=0;i
8/2/2019 Final Expert Level c Aptitude Round
5/23
CORRECT
ANSWER
5 | P a g e
to a function which receives two pointers to int pointers and returns a pointer toan int pointer.
C) f is a pointer which returns a pointer to an int pointer and receives as itsparameters an integer and a pointer to a function which receives nothing andreturns pointer to int pointer
D) f is a function that returns a pointer to an array of pointers to functiontofunctions that return a pointer to an int pointer.12)What will be the output of the following program?
int main(){char near * near * ptr1;
char near * far * ptr2;char near * huge * ptr3;
printf(%d %d %d,sizeof(ptr1),sizeof(ptr2),sizeof(ptr3));
}
A) 2 4 4B) 4 4 2C) 2 2 2D) 4 4 413)Which of the following is the correct output?
int main(){
unsigned int res;
res=(64>>(2+1-2))&(~(1
8/2/2019 Final Expert Level c Aptitude Round
6/23
CORRECT
ANSWER
6 | P a g e
C) All ZerosD) 8 0
0 032 00 16
15)Which of the following statements are correct?int main(){
unsigned int m[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};unsigned char n,i;
scanf(%d,&n);for(i=0;i
8/2/2019 Final Expert Level c Aptitude Round
7/23
CORRECT
ANSWER
7 | P a g e
typedef float f;static f *fptr;
float fval=90;
fptr=&fval;printf(\n%f,*fptr);
return 0;}
A) 9B) 0C) 90.000000D) 9018)Which of the following output is correct?
int main(){
int i=4,j=-1,k=0,w,x,y,z;w=i || j ||k;x=i && j && k;
y=i || j && k;z=i && j || k;printf(%d %d %d %d,w,x,y,z);
return 0;
}
A) 1 1 1 1B) 1 1 0 1C) 1 0 0 1D) 0 1 1 1E) 1 0 1 1
19)Which of the following output is correct?int fun(int,int);typedef int (*pf) (int,int);
int proc (pf,int,int);
int main(){
printf(%d\n,proc(fun,6,6));
return 0;
}
int fun(int a,int b){
return (a==b)
}int proc(pf p,int a,int b){
return ((*p)(a,b));
}
A) 6
8/2/2019 Final Expert Level c Aptitude Round
8/23
CORRECT
ANSWER
8 | P a g e
B) 1C) 0D) -120)Which of the following output is correct?
int main(){static int arr[]={0,1,2,3,4};
int *p[]={arr,arr+1,arr+3,arr+4};
int **ptr=p;ptr++;
printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr);*ptr++;
printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr);
*++ptr;printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr);++*ptr;
printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr);return 0;
}
A) 0 0 01 1 1
2 2 23 3 3
B) 1 1 22 2 33 3 4
4 4 1
C) 1 1 12 2 2
3 34 4 4
D) 1 1 12 3 33 4 4
3 5 Garbage
21)Which of the following is the correct output in gcc under linux?int main(){
enum value{VAL1,VaL2,VaL3,VAL4,VAL5}var;
printf(\n%d,sizeof(var));
return 0;}
8/2/2019 Final Expert Level c Aptitude Round
9/23
CORRECT
ANSWER
9 | P a g e
A) 1B) 2C) 4D) 10
22)Which of the following is the correct output for the program givenbelow if a short int is 2 bytes wide ?
#includeint main()
{
short int i=0;for(i=-1;++I;i>0)
printf(%u\n,i);
printf(\n);return 0;}
A. 165535
B. Expression syntax errorC. No OutputD. 0 1 2 3 4 5
23)Which of the following statements are correct about the C programgiven below ?
# include
int main()
{int x=10,y=100%90;for(i=1;i
8/2/2019 Final Expert Level c Aptitude Round
10/23
CORRECT
ANSWER
10 | P a g e
while(i=0) printf(%d,i);
i=5;
printf(\n);while(i=0) printf(%i,i);
printf(\n);
return 0;}
A. 4 3 2 1 0 -14 3 2 1 0 -1
B. 5 4 3 2 1 05 4 3 2 1 0
C. Error
D. 5 4 3 2 1 05 4 3 2 1 0
5 4 3 2 1 0
25)Which of the following is the correct output for the program given below ?#include
int main()
{unsigned int i=65535; /* assume a 2-byte integer */while(i++!=0)
printf(%d,++i);
printf(\n);return 0;
}
A. Infinite loopB. 0 1 265535C. 1 2 .32767 -32766 -32765.-1 0
D. No output
26)What will be the output of the following program ?#include#define MIN(x,y) (x
8/2/2019 Final Expert Level c Aptitude Round
11/23
CORRECT
ANSWER
11 | P a g e
27)Which of the following is the stage at which the statement#include
gets replaced by the contents of the file stdio.h ?
A) During editingB) During linkingC) During executionD) During preprocessingE) During compilation
28) Which of the following is the correct output for the program given below ?#includeint main()
{int arr[3] = {2,3,4};
char *p;
p = arr;p= (char *) ((int *)(p));
printf(%d,*p);p=(int *)(p+1);
printf(%d \n,*p);return 0;
}
A) 2 3 4B) 2 0C) 2D) Garbage values
29) Which of the following is the correct output for the program given below ?
#include
int main(){
int arr[3]={2,3,4};
char *p;p=arr;p=(char*)((int*)(p));
printf("%d",*p);p=(int*)(p+1);
printf("%d\n",*p);return 0;
}
A) 2 3 4
B) 2 0C) 2D) Garbage values
8/2/2019 Final Expert Level c Aptitude Round
12/23
CORRECT
ANSWER
12 | P a g e
30) Which of the following is the correct output for the program given below?
#include
int main(){
void *vp;char ch=74,*cp="JACK";
int j=65;vp=&ch;
printf("%c",*(char*)vp);
vp=&j;printf("%c",*(int*)vp);
vp=cp;printf("%s\n",(char*)vp+2);
return 0;
}
A) JCK
B) J65KC) JAKD) JACK
31) Which of the following is the correct output for the program given below ?
#include
void fun(void *p)
int i;
int main(){
void *vptr;vptr=&i;fun(vptr);return 0;
}void fun(void *p){
int **q;q=(int**)&p;printf("%d\n",**q);
}
A) Error:Cannot convert from void ** to int**
B) Garbage value
C) 0D) No output
8/2/2019 Final Expert Level c Aptitude Round
13/23
CORRECT
ANSWER
13 | P a g e
32) Which of the following is the correct output for the program given below?
#include
int main(){
int i,*j,k;i=3;
j=&i;printf("%d\n",i**j*i+*j);
return 0;
}
A) 30B) 27
C) 9
D) 3
33) Which of the following is the correct output for the program given below?
#include
int *check(static int,static int);
int main(){
int *c;
c=check(10,20);
printf("%d\n",*c);return 0;
}
int *check(static int i,static int j)
{ int *p,*q;
p=&i;q=&j;if(i>=45)return(p);
elsereturn(q);
}
A) 10B) 20
C) Error: 'Non portable pointer conversion'
D) Error: 'Cannot use static for function parameters'
34) Which of the following statement is correct about k used in the statement given below?
char****k;
8/2/2019 Final Expert Level c Aptitude Round
14/23
CORRECT
ANSWER
14 | P a g e
A) k is pointer to a pointer to a pointer to a charB) k is pointer to a pointer to a pointer to a pointer to a char
C) k is pointer to a char pointer
D) k is pointer to a pointer to a char
35) Which of the following statements correctly declare a function that receives a pointer toa pointer to a pointer to a float and returns a pointer to a pointer to a pointer to a pointer to
a float ?
A) float** fun(float ***);
B) float* fun(float ***);C) float fun(float ***);
D) float **** fun(float ***);
36) Which of the following statements is correct about the program given below ?
int main()
{
int arr[3][3] = {1,2,3,4};printf("%d\n",*(*(*(arr))));return 0;
}
A) It will output a garbage value
B) It will output a value 1
C) It will output a value 1
D) It will report an error: 'Invalid indirection'
37) Which of the following statement is true about the program given below ?
#includeint main(){
float a=3.14;char *j;j=(char *)&a;
printf("%d\n",*j);
return 0;}
A) It will print ASCII value of the binary number present in the first byte of the floatvariable a.B) It will print character equivalent of the binary number present int the first byte of the
float variable a.
C) It will print 3.D) It will print a garbage value
8/2/2019 Final Expert Level c Aptitude Round
15/23
CORRECT
ANSWER
15 | P a g e
38) Which of the following statement is true about the program given below ?
#includepower(int**);
int main(){
int a=5,*aa; /* Suppose the address of the variable a is 1000 */
aa=&a;a=power(&aa);
printf("%d\n",a);return 0;
}
power(int **ptr){
int b;
b=**ptr***ptr;return(b);
}
A) 5B) 25C) 125
D) Garbage value
39) What will be the output of the following program if the size of the
pointer is considered as 4 bytes ?
#includeint main(){
printf("%d %d\n",sizeof(NULL),sizeof(**));
return 0;}
A) 00B) 01C) 11
D) 41
40) Which of the following is the correct output for the program given below?
#include
int main()
{int i;
8/2/2019 Final Expert Level c Aptitude Round
16/23
CORRECT
ANSWER
16 | P a g e
char a[]="\0";if(printf("%s",a))
printf("String is not empty\n");
elseprintf("The string is empty\n");
return 0;}
A) The string is not emptyB) The string is empty
C) No output
D) 0
41) Which of the following is the correct output for the program given below?
#include
int main(){
char str1[]="Hellow";
char str2[]="Hellow";
if(str1==str2)printf("Equal\n");else
printf("Unequal\n");
return 0;}
A) Equal
B) UnequalC) Error
D) None of the above
42) Which of the following is the correct output for the program given below?
#include
int main(){
printf("Icecream""Chocolate pie\n");
return 0;
}
A) Error
B) Icecream chocolate pieC) IcecreamD) Chocoloate pie
8/2/2019 Final Expert Level c Aptitude Round
17/23
CORRECT
ANSWER
17 | P a g e
43) Which of the following is the correct output for the program given below?
#include
#includeint main()
{char str1[20]="Hell0",str2[20]="Word";
printf("%s\n",strcpy(str2,strcat(str1,str2)));return 0;
}
A) Hello
B) WorldC) Hello World
D) WorldHello
44) Which of the following is the correct output for the program given below?
#include
int main()
{int i;char a[]="\0";
if(printf("%s",a))
printf("The string is not empty\n");else
printf(''The string is empty\n");
return 0;
}
A) The string is not emptyB) The string is emptyC) No outputD) 0
45) Which of the following is the correct output for the program given below?
#include
int main()
{char str1[]="Hello";
char str2[]="Hello";
if(str1==str2)printf("Equal\n");else
printf("Unequal\r");
return 0;}
8/2/2019 Final Expert Level c Aptitude Round
18/23
CORRECT
ANSWER
18 | P a g e
A) Equal
B) Unequal
C) ErrorD) None of the above
46) Which of the following is the correct output for the program given below ?
#includeint main()
{printf("Icecream""Chocolate pie\n");
return 0;
}
A) Error
B) Icecream Chocolate pieC) IcecreamD) Chocolate pie
47) Which of the following is the correct output for the program given below ?
#include#include
int main()
{
chr str1[20]="Hello",str2[20]="World";printf("%s\n",strcpy(str2,strcat(str1,str2)));
return 0;}
A) Hello
B) WorldC) Hello WorldD) WorldHello
48) Which of the following is the correct output for the program given below ?
#includeint main()
{
char str[]="sales\0man\0";printf("%d\n",sizeof(str));return 0;
}
A) 10
8/2/2019 Final Expert Level c Aptitude Round
19/23
CORRECT
ANSWER
19 | P a g e
B) 6C) 5
D) 11
49) Which of the following is the correct output for the program given below ?
#include
int main(){
Union a{
Int I;
Char ch[2];};Union a u1 = {512};
Union a u2 = (0,2);Return 0;}
A) u2 CANNOT be initialized as shownB) u1 can be initialized as shown.C) To initialize char ch[] of u2 . Operator should be used.
D) All above
50) Which of the following is the correct output for the program given below ?
#includeint main()
{Struct byte
{Int one:1;
};Struct byte var = {1};Printf(%d\n,var.one);
Return 0;}
A) 1
B) -1C) 0
D) Error
51) Which of the following is the correct output for the program given below ?
#includeint main()
8/2/2019 Final Expert Level c Aptitude Round
20/23
CORRECT
ANSWER
20 | P a g e
{Union a
{
Int i;Char ch[2];
};Union a u;
u.ch[0]=3;u.ch[1]=2;
printf(%d%d%d\n,u.ch[0],u.ch[1],u.i);
return 0;}
A) 3 2 515
B) 515 2 3
C) 3 2 5D) None of the above
52) Which of the following is the correct output for the program given below ?
#include
int main()
{Unsigned int num;Int c=0;
Scanf(%u,&num);
for(;num;num>=1){
If(num &1)c++;
}
Printf(%d\n,c);Return 0;
}
A)It counts the number of bits that are on in the number num.B) It sets all bits in the number num to 1.
C) It sets all bits in the number num to 0D) None of the above
53) Which of the following is the correct output for the program given below ?#include
#include
int main(){
float n=1.54;
printf(%f%f\n,ceil(n),floor(n));
return 0;}
8/2/2019 Final Expert Level c Aptitude Round
21/23
CORRECT
ANSWER
21 | P a g e
A) 2.000000 1.000000B) 1.500000 1.500000
C) 1.550000 2.000000
D) 1.000000 2.000000
54) Which of the following is the correct output for the program given below ?#include
int main(){
printf(%d%d%d\n,sizeof(3.14f),sizeof(3.14),sizeof(3.14l));
return 0;}
A) 4 4 4B) 4 8 8
C) 4 8 10
D) 4 8 12
55) What will be the output of the following program ?
#include#define FUN(I,J) i##jint main()
{
int val1=10;int val12=20;printf(%d\n,FUN(val1,2));
return 0;
}A) 10
B) 20
C) 1020
D) 12
56) What will be the output of the following program ?#includeint main(){
char c=48;int I,mask=01;for(i=1;i
8/2/2019 Final Expert Level c Aptitude Round
22/23
CORRECT
ANSWER
22 | P a g e
#include#include
int main()
{int *p;
p=(int*)malloc(256*256);if(p==NULL)
printf(Allocation failed);return 0;
}
A) Run Time ErrorB) Segmentation FaultC) It will print Allocation FailedD) Linker Error
58) Will the following code work at all times ?
#includeint main(){
char *ptr;
gets(ptr);printf(%s\n,ptr);return 0;
}
A) Run Time ErrorB) Memory not allocated for ptrC)
Stack overflowD) Linker Error
59) which of the following is correct order of calling function is code snippet givenbelow
a=f1(23,14)* f2(12/4)+f3();
a)f1,f2,f3
b)f3,f2,f1
c)The order may vary from compiler to compiler
d) None of above
8/2/2019 Final Expert Level c Aptitude Round
23/23
CORRECT
ANSWER
23 | P a g e
60) what will be the output of the following programint main()
{
int i=-3,j=2,k=0,m;
m=++i&&++j && ++k;
printf(%d%d%d\n,i,j,k,m);
return 0;
}
A) -2 3 0B) -2 3 1C) -2 -2 -2D) 0 0 0