Monday, June 24, 2013

C++ MCQ Test - 2

Que.1 .  What is shallow copy?



A:            A shallow copy creates a copy of the dynamically allocated objects too.

B:            A shallow copy just copies the values of the data as they are.

C:            A shallow copy creates a copy of the statically allocated objects too

D:            Both b and c above



Right Answer: B



Que.2 .  An abstract class can be instantiated.



A:            True

B:            False



Right Answer: B



Que.3 .  Which of the following below can perform conversions between pointers to related classes?



A:            cast_static

B:            dynamic_cast

C:            static_cast

D:            cast_dynamic



Right Answer: C



Que.4 .  Can #define accept parameters?



A:            Yes

B:            No



Right Answer: A



Que.5 .  What is the difference between overloaded functions and overridden functions?



A:            Overloading is a dynamic or run-time binding and Overriding is static or compile-time binding

B:            Redefining a function in a friend class is called function overriding while Redefining a function in a derived class is called a overloaded fucntion.

C:            Overloading is a static or compile-time binding and Overriding is dynamic or run-time binding

D:            Redefining a function in a friend class is called function overloading while Redefining a function in a derived class is called as overridden fucnion.



Right Answer: C



Que.6 .  How do we define a destructor?



A:            X~() {}

B:            X() {}~

C:            X() ~{}

D:            ~X() {}



Right Answer: D



Que.7 .  Which classes allow primitive types to be accessed as objects?



A:            Storage

B:            Virtual

C:            Friend

D:            Wrapper



Right Answer: D



Que.8 .  Can constructors be overloaded?



A:            No

B:            Yes



Right Answer: B



Que.9 .  #if or #elif can be used to evaluate



A:            Constant expressions

B:            Macro expressions

C:            Both a and b

D:            All expressions



Right Answer: C



Que.10 .  The default access level assigned to members of a class is ___________



A:            Private

B:            Public

C:            Protected

D:            Needs to be assigned



Right Answer: A



Que.11 .  Which type of casting can be used only with pointers and references to objects?



A:            Dynamic_cast

B:            cast

C:            Static_cast

D:            Pointer_Cast



Right Answer: A

Que.12 .  Which of the following below is /are a valid iterator type?



A:            Input Iterator

B:            Backward Iterator

C:            Forward Iterator

D:            Both a and c above



Right Answer: D



Que.13 .  Which of the following is not a standard exception built in C++.



A:            std::bad_creat

B:            std::bad_alloc

C:            std::bad_cast

D:            std::bad_typeid



Right Answer: A



Que.14 .  Every class has at least one constructor function, even when none is declared.

A:            True

B:            False

Right Answer: A

Que.15 .  Which of the following is not a valid conditional inclusions in preprocessor directives

A:            #ifdef

B:            #ifundef

C:            #endif

D:            #elif

Right Answer: B

Que.16 .  In C++ two different functions can have the same name if their parameter types are same.

A:            True

B:            False

Right Answer: B

Que.17 .  Which of the following operators below allow to define the member functions of a class outside the class?

A:            ::

B:            ?

C:            :?

D:            %



Right Answer: A

Que.18 .  Inline functions are invoked at the time of


A:            Run time

B:            Compile time

C:            Depends on how it is invoked

D:            Both b and c above



Right Answer: B



Que.19 .  For which type of class private and protected members of the class can be accessed from outside the same class in which they are declared



A:            No such class exist

B:            Friend

C:            Static

D:            Virtual



Right Answer: B


Que.20 .  What is reinterpret_cast used for?


A:            converts integer pointer type to any other integer pointer type

B:            Converts any pointer type to any other pointer type

C:            converts any pointer type to only integer pointer type

D:            Both a and b


Right Answer: D


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