These multiple-choice questions related to computer science. These Mcqs are given from the book which will helps to prepare you for the test and learn basic knowledge about C++programming
1.C++ was originally developed by
(a) Clocksin and Mellish
(b) Donald E. Knuth
(c) Sir Richard Hadlee
(d) Bjarne Stroustrup
2.C front
(a) is the front end of a C compiler
(b) is the pre-processor of a C compiler
(c) is a tool that translates a C++ code to its equivalent C code
(d) none of the above
3.The following program fragment int
Int i=10;
Void main { }
Int i=20;
{
Int i=30.;
Cout << i << ::i;
}
}
(a) prints 3010
(b) prints 3020
(c) will result in a run time error
(d) none of the above
4. Which of the following are procedural languages?
(a) Pascal
(b) Smalltalk
(c) C++
(d) C
5. A function abc is defined as
void abc(int x=0, int y=0)
{ cout << x << y; } Which of the following function calls is/are illegal? (Assume h, g are declared as initegers)
(a) abc ();
(b) abc ( h) ;
(c) abc (h,h);
(d) None of the above
6.The following C++ code results in
include “iostream.h”
void main(void)
{
cout << (int i=5) << (int j=6):
}
(a) compilation error
(b) run time error
(c) link time error
(d) none of the above
7. Reusability is a desirable feature of a language as it
(a) decreases the testing time
(b) lowers the maintenance cost
(c) reduces the compilation time
(d) reduces the execution time
8. Choose the correct statements regarding inline functions.
(a) It speeds up execution
(b) It slows down execution
(c) It increases the code size
(d) It decreases the code size
9. If many functions have the same name, which of the following information. if present.
will be used by the compiler to invoke the correct function to be used?
(a) The operator : :
(b) The return value of the function
(c)Function signature
(d) None ofthe above
10. The statements
int a = 5;
cout << “FIRST” << (a<<2) << “SECOND”;
outputs
(a) FIRST 2 SECOND
(b) FIRST 2O SECOND
(C) SECOND 25 FIRST
(d) an error message
11. Choose the correct remarks.
(a) C++ allows any operator to be overloaded.
(b) Some of the existing operators cannot be overloaded.
(c) Operator precedence cannot be changed.
(d) All of the above.
12. A constructor is called whenever
(a) an object is declared
(b) an object is used
(c) a class is declared
(d) a class is used
13. Which of the following remarks about the differences between constructors and destructors are correct?
(a) Constructors can take arguments but destructors cannot.
(b) Constructors can be overloaded but destructors cannot be overloaded.
(c) Destructors can take arguments but constructors cannot.
(d) Destructors can be overloaded but constructors cannot be overloaded.
14. The following program fragment
void main( )
{ int x=10;
int &p=x;
cout <<. &p << &x;
}
(a) prints 10 and the address of x
(b) Result in a run time error
(c) prints the address of x twice
(d) Print the address of p twice
15. The declaration
int x; int &p=x;
is same as the declaration int x.*p; p=&x:
This remark is
(a) true
(b) false
(c)sometime true
(d) none of the above
16. The following program segment
const int m=10;
int &n=m;
n=11;
Cout << m << n;
(a) results in compile time error
(b) result in run time error
(c) prints 1111
(d) print 1011
17. The following program segment
int a=10;
int const &b=a;
a=11;
cout << a << b;
(a) results in compile time error
(b) result in a run time error
(c) prints 1111
(d) none of the above
31. If the function chg is coded as
int chg(int x)
{
x = 10;
return (11);
then
(a) it results in compile-time error
(b) it results in run time error
(c) it prints 112
(d)it prints 1110
32. If the function chg is coded as
int chg(int &x)
{
x 10;
return(11);
}
then
(a) it results in compile-time error
(b) it results in run time error
(c) it prints 112
(d)it prints 1110
34. Choose the correct statements from the following:
(a) In a struct, the access control is public by default.
(b) In a struct, the access control is private by default.
(c) In a class. the access control is public by default.
(d) In a class, the access control is private by default.
48. The variable 12 is accessible
(a) to a public function in class A
(b) to a public function in class B
(c) to a public function in class C
(d) from the main function
49. Which variable(s) is/are accessible from the main function?
(a) i I
(b) i2
(c) i 3
(d) None of the above
50.. The following program
class abc;
class def
( int i l; // statement 1
protected: int i2; // statement 2
public: int i3; // statement 3
friend abc;
};
class abc
{ public:
void main(def A)
(cout << (A.i1=3); cout << (A.i2=4); cout << (A.i3=5))
);
void main( )
{
def. Xl;
abc x2;
x2.mn(x1);
(a) will compile successfully if statement 1 is removed
(b) will compile successfully if statement 2 is removed
(c) will compile successfully if statement 3 is removed
(d) will run successfully and print 345
51.The above program
(a) results in compilation error
(b) prints 123
(c) prints 111
(d) prints 322
52. If the statement
q += b(a(q)); is replaced by the statement
q += b(a(p)): then the above program
(a) prints III
(b) results in compilation error
(c) prints 322
(d)prints 352
53. Consider the declarations
char a;
const char aa = ‘h’;
char “na;
const char *naa;
Which of the following statements
Statements 1: aa = a;
Statement II: na a &a;
Statement na a &aa;
is/are illegal?
(a) Only I and II
(b) Only II and III
(c) Only I and III
(d) All the three statements are illegal
54. Forgetting to include a file (like cmath or math.h) that is necessary will result in
(a) compilation error
(b) warning when the program is run
(c) error at link time
(d) warning when the program is compiled
55. Assume that the random number generating function – rand( ), returns an integer between 0 and 10000 (both inclusive). If you want to simulate the throwing of a die using this random function, use the expression
(a) rand( ) % 6
(b) nuxI( ) % 6 + I
(c) rand() % 5 + I
(d) none of the above
56. Assume that the random number generating function – rand( returns an integer between 0 and 10000 (both inclusive). To randomly generate a number between a and b (both inclu-sive), use the expression
(a) rand( ) % (b-a)
(b) (rand( ) % a) + b
(c) (rand( ) % (b-a)) + a
(d) (rand( ) % (b-a+1)) + a
57. Which of the following comments about inline comments are true?
(a) A function is declared inline by typing the keyword inline before the return value of the function.
(b) A function is declared inline by typing the keyword inline after the return value of the function.
(c) A function that is declared inane may not be treated inline.
(d) Inline functions are essentially same as implementing a function as macro.
58. Which of the following decides if a function that is declared inline is indeed going to be treated inline in the executable code?
(a) Compiler
(b) Linker
(c) Loader
(d) Preprocessor
59. Which of the following type of functions is an ideal candidate for being declared inline?
(a) A function that is small and is not called frequently.
(b) A function that is small and is called frequently.
(c) A function that is not small and is not called frequently.
(d) A function that is not small and is called frequently.
60. One of the disadvantages of pass-by-reference is that the called function may inadvertently corrupt the caller’s data. This can be avoided by
(a) passing pointers
(b) declaring the formal parameters constant
(c) declaring the actual parameters constant
(d) all of the above
Check Also: System software MCQS
Source link : https://books.google.com.pk/books?id=5tatBaRplIgC&pg