Monday, June 24, 2013

C MCQ Test - 2

Que.1 .  va_list is an array that holds information needed by va_arg and va_end

A: null

B: null

C: null

D: null



Right Answer: A



Que.2. Point out the error in the following program.

#include<stdio.h>

#include<stdarg.h> void varfun(int n, ...); int main()

{

varfun(3,7, -11.2,0.66);

return 0;

}

void varfun( int n, ...)

{

float *ptr; int num; va_start(ptr, n);

num = va_arg(ptr, int);

printf("%d", num);

}



A: null

B: null

C: null

D: null



Right Answer: C



Que.3. What is the output of the program?

typedef struct data;

{

int x;

sdata *b;

}sdata;



A: stdio.h

B: stdarg.h

C: Error: too many parameters

D: Error: invalid access to list member



Right Answer: A



Que.4. How do we declare a float pointer?



A: float *ptr;

B: float ptr;

C: *float ptr;

D: None of the above



Right Answer: A



Que.5. Which of the following errors would be reported by the compiler on compiling the program given below?

#include<stdio.h>

int main()

{

int a =5;

switch(a)

{

case 1: printf("First"); case 2: printf("Second"); case 3 + 2: printf("Third"); case 5 : printf("Final"); break;

}

return 0;

}



There is no

A: break statement in each case. Expression as in

B: case 3 + 2 is not allowed. Duplicate case

C: case 5:

D: No error will be reported.



Right Answer: C



Que.6. Which header file should you include, if you are going to develop a function, which can accept variable number of arguments?



Error: ptr must be type of

A:va_list

B: No error

C: True

D: False



Right Answer: D



Que.7. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=2;

printf("%d, %d", ++i, ++i);

return 0;

}



A: 3, 4

B: 4, 3

C: 4, 4

D: Output may vary from compiler to compiler



Right Answer: D



Que.8. How many times the while loop will get executed if a short int is 2 byte wide?

#include<stdio.h>

int main()

{

int j=1;

while(j <= 255)

{

printf("%c %d", j, j);

j++;

}

return 0 ;

}



A: Infinite times

B: 255 times

C: 256 times

D: 254 times



Right Answer: B



Que.9. When an Array passed as an argument to a function, it is interpreted as



A: Number of element of the array

B: Address of the array

C: Address of the first element of the array

D: Values of the first elements of the array



Right Answer: C



Que.10 .  Point out the error, if any in the program.

#include<stdio.h>

int main()

{

int P = 10;

switch(P)

{

case 10: printf("Case 1"); case 20: printf("Case 2"); break;

case P: printf("Case 2"); break;

}

return 0;

}



A: Error: No default value is specified Error: Constant expression required at line

B:case P: Error: There is no

C: break statement in each case.

D: No error will be reported.



Right Answer: B



Que.11. In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators



A: True

B: False

1. KR Notation

C:

2. ANSI Notation

1. Pre ANSI C Notation

D:

2. KR Notation



Right Answer: B



Que.12. Output of the following program:

main()

{

char str[]="S65AB";

printf("%d", sizeof(str));

}



A: 7

B: 6

C: 5

D: error



Right Answer: C



Que.13. void main()

{

int i; printf("%d",i^i);

}



A: cannot compile

B: 0

C: Unexpected

D: Runtime Error



Right Answer: B



Que.14. What is the notation for following functions?

1. intf(int a,float b)

{

/* Some code */

}

2. int f(a, b)int a;float b;

{

/* Some code */

}



1. ANSI Notation

A:

2. KR Notation

1. ANSI Notation

B:

2. Pre ANSI Notation

C: Infinite times

D: 32767 times



Right Answer: C



Que.15. Which of the following statement is correct about the program?

#include<stdio.h>

int main()

{

FILE *fp; char ch; int i= 1;

fp = fopen("myfile.c","r");

while((ch=getc(fp))!=EOF)

{

if (ch == )

i++;

} fclose(fp); return 0;

}



A: True

B: False

C: 12400

D: 12480



Right Answer: D



Que.16. Bit fields CANNOT be used in union. ?

A: The code counts number of characters in the file

B: The code counts number of words in the file

C: The code counts number of blank lines in the file

D: The code counts number of lines in the file



Right Answer: B



Que.17.  How many times the program will print "HelloWorld" ?

#include<stdio.h>

int main()

{ printf("IndiaBIX"); main();

return 0;

}



A: 65535 times

B: 10

C: 11

D: Till stack overflows



Right Answer: D



Que.18. What will be the output of the program?

#include<stdio.h>

#define SQR(x)(x*x)

int main()

{

int a, b=3;

a = SQR(b+2); printf("%d", a); return 0;

}



A: Error

B: Garbage value

C: True

D: False



Right Answer: B



Que.19. What will be the output of the program?

#include<stdio.h>

int main()

{

char c=48;

int i, mask=01;

for(i=1; i<=5; i++)

{

printf("%c", c|mask);

mask = mask<<1;

}

return 0;

}



A: No error

B: None of above

C: varagrg.h

D: stdlib.h



Right Answer: B



Que.20. The first argument to be supplied at command-line must always be count of total arguments



A: 12500

B: 12556

C: Error: Declaration missing ';' Error: in

D: typedef



Right Answer: B


No comments:

Post a Comment