Site icon T4Tutorials.com

Advanced C++ MCQs

1. What is the output of the following code?
int x=10; int y=20; cout << (x<y && x>5);

(A) 0


(B) 1


(C) 10


(D) 20



2. Which of the following is the correct way to declare a pure virtual function?

(A) virtual void func() = 0;


(B) void virtual func() = 0;


(C) virtual void func() {}


(D) void func() = virtual;



3. Output?
int x=5; int y=++x*3; cout << y;

(A) 18


(B) 15


(C) 20


(D) 17



4. What is the output?
char str[]="ABC"; cout << str[1];

(A) A


(B) B


(C) C


(D) Compilation error



5. Which of the following is correct syntax for array initialization?

(A) int arr[3]={1,2,3};


(B) int arr[]={1,2,3};


(C) int arr[3]={1,2};


(D) All of the above



6. Which of the following is NOT a valid C++ data type?

(A) short


(B) float


(C) real


(D) long



7. Output?
int a=5, b=2; cout << a%b;

(A) 1


(B) 2


(C) 0


(D) 3



8. What is the output?
int x=1; if(x==1) cout << "True"; else cout << "False";

(A) True


(B) False


(C) 1


(D) 0



9. Which of the following is correct about operator precedence?

(A) * has higher precedence than +


(B) + has higher precedence than *


(C) == has higher precedence than *


(D) = has higher precedence than ==



10. Which of the following is true for friend function?

(A) Cannot take arguments


(B) Must be member function


(C) Can access private and protected members


(D) Cannot return values



11. Output?
int a=2; cout << a<<++a;

(A) 23


(B) 33


(C) 24


(D) Undefined behavior



12. Which of the following is true about references?

(A) Cannot be NULL


(B) Can be reassigned


(C) Declared with *


(D) Only works with classes



13. Output?
int a=5; cout << sizeof(a);

(A) 2


(B) 4


(C) 8


(D) Depends on compiler



14. Which of the following is a correct STL container?

(A) vector


(B) stack


(C) queue


(D) All of the above



15. Which of the following is true about templates?

(A) Only works with int


(B) Enables generic programming


(C) Cannot return value


(D) Cannot have multiple parameters



16. Output?
int x=1; x=x<<3; cout << x;

(A) 1


(B) 8


(C) 3


(D) 0



17. Which of the following is correct way to call a base class constructor from derived class?

(A) Derived() : Base() {}


(B) Derived() { Base(); }


(C) Base() : Derived() {}


(D) Base() {}



18. Output?
int x=10; int* p=&x; cout << p;

(A) 10


(B) Address of x


(C) 0


(D) Compilation error



19. Which of the following is correct way to swap two integers using pointers?

(A) void swap(int* a, int* b){ int t=*a; *a=*b; *b=t; }


(B) void swap(int a, int b){ int t=a; a=b; b=t; }


(C) void swap(int &a, int &b){ int t=a; a=b; b=t; }


(D) void swap(int a, int* b){ int t=a; a=*b; *b=t; }



20. Output?
int a=10; cout << ++a << a++;

(A) 11 11


(B) 11 12


(C) 12 11


(D) 10 11



21. Which of the following is correct about virtual destructor?

(A) Ensures derived destructor is called


(B) Must be pure


(C) Cannot have parameters


(D) Cannot have body



22. Output?
int a=5; cout << a>>1;

(A) 2


(B) 2.5


(C) Compilation error


(D) 5



23. Which of the following is correct to declare a 2D array?

(A) int arr[2][3];


(B) int arr[3][2];


(C) int arr[][]=new int[2][3];


(D) Both A and B



24. Output?
int a=5; int b=3; cout << a|b;

(A) 6


(B) 7


(C) 1


(D) 0



25. Which of the following is NOT a valid member access?

member’)”> (A) obj.member


member’)”> (B) ptr->member


member’)”> (C) obj->member


member’)”> (D) (*ptr).member



26. Which of the following is true about inline function?

(A) Reduces function call overhead


(B) Always increases code size


(C) Cannot take parameters


(D) Must return void



27. Output?
int a=10; int b=20; cout << (a!=b);

(A) 0


(B) 1


(C) 10


(D) 20



28. Which of the following is a correct way to allocate dynamic memory for int array?

(A) int* p=new int[10];


(B) int* p=(int*)malloc(10);


(C) int* p=new int;


(D) int p[10];



29. Which of the following is correct for multiple inheritance?

(A) class C : public A, public B {}


(B) class C : A : B {}


(C) class C : A, B {}


(D) class C : B : A {}



30. Output?
int a=2; int b=3; cout << (a&&b);

(A) 0


(B) 1


(C) 2


(D) 3



31. Which of the following is true about scope resolution operator (::)?

(A) Accesses global variables


(B) Accesses class static members


(C) Both A and B


(D) None



32. Output?
int x=5; int y=++x + ++x; cout << y;

(A) 12


(B) 13


(C) 11


(D) Undefined behavior



33. Which of the following is correct about const function in class?

(A) Cannot modify any class member


(B) Cannot call non-const member functions


(C) Both A and B


(D) None



34. Output?
int x=10; cout << (x>>2);

(A) 2


(B) 2.5


(C) 3


(D) 40



35. Which of the following is correct about try-catch block?

(A) catch must immediately follow try


(B) Multiple catch allowed


(C) Both A and B


(D) None



36. Output?
int a=5; int b=10; cout << (a>b ? a : b);

(A) 5


(B) 10


(C) 0


(D) Compilation error



37. Which of the following is true for char arrays?

(A) Always null-terminated


(B) Can store numbers


(C) Can be used as strings


(D) Both A and C



38. Output?
int arr[]={1,2,3,4}; cout << sizeof(arr)/sizeof(arr[0]);

(A) 3


(B) 4


(C) 1


(D) Compilation error



39. Which of the following is true about default arguments?

(A) Must be at end of parameter list


(B) Can be anywhere


(C) Cannot have multiple defaults


(D) None



40. Output?
int x=1; int y=2; cout << (x<y? x:y);

(A) 1


(B) 2


(C) 0


(D) Compilation error



41. Which of the following is NOT a valid C++ comment?

(A) // Comment


(B) /* Comment */


(C) # Comment


(D) Both A and B are valid



42. Output?
int a=10; int* p=&a; *p=20; cout << a;

(A) 10


(B) 20


(C) Address


(D) Compilation error



43. Which of the following is correct for overloading << operator?

(A) ostream& operator<<(ostream &out, const Class &obj){}


(B) void operator<<(Class &obj){}


(C) Class operator<<(ostream &out){}


(D) ostream operator<<(Class &obj){}



44. Output?
int x=5; cout << (x>0 ? "Positive" : "Negative");

(A) Compilation error


(B) Negative


(C) 5


(D) Positive



45. Which of the following is true about typecasting?

(A) static_cast checks type at compile time


(B) dynamic_cast checks type at runtime


(C) reinterpret_cast allows low-level cast


(D) All of the above



46. Output?
int x=3; int y=x++ + ++x; cout << y;

(A) 7


(B) 8


(C) 9


(D) Undefined behavior



47. Which of the following is true about STL map?

(A) Stores unique keys


(B) Key-value pairs


(C) Sorted by key


(D) All of the above



48. Output?
int x=5; int* p=NULL; cout << *p;

(A) 0


(B) Garbage


(C) Runtime error


(D) Compilation error



49. Which of the following is correct about static member function?

(A) Cannot access non-static members


(B) Belongs to class, not object


(C) Can be called using class name


(D) All of the above



50. Output?
int a=10; cout << a– << –a;

(A) 10 8


(B) 10 9


(C) 9 8


(D) 11 9



1. Processor that translates the source code into object code as a whole is called…

(A) Assembler


(B) Linker


(C) Compiler


(D) Debugger



2. ……….. is a procedural language…

(A) FORTRAN


(B) C


(C) ADA


(D) All of these



3. Bjarne Stroustrup developed…

(A) C language


(B) C++


(C) BASIC


(D) FORTRAN



4. Between the angle brackets the name of ………. is given…

(A) Header file


(B) Functions


(C) Body


(D) None of them



5. Which of the following is true about a header file…

(A) Definitions of various constants


(B) Definitions of various data types


(C) Prototypes of standard library functions


(D) All of the above



6. If a semicolon is not used at the end of a statement, what message will be displayed by C++?

(A) Semicolon missing


(B) Terminator missing


(C) Error in statements


(D) Statement missing



7. The linker creates a file with the extension…

(A) .cpp


(B) .ccp


(C) .obj


(D) .exe



8. The term used for running the program on the computer is…

(A) Compiling


(B) Loading


(C) Linking


(D) Executing



9. Syntax errors occur due to…

(A) Missing semicolon


(B) Incorrect spelling


(C) Missing any brace


(D) Program without declaring



10. Shortcut key used to compile and run the program in C++ is…

(A) Alt+F9


(B) Alt+F5


(C) Ctrl+F9


(D) F9



11. A compiler can detect which type of error?

(A) Logical error


(B) Runtime error


(C) Syntax error


(D) All of these



12. Which of the following operators can be categorized…

(A) Binary operators


(B) Unary operators


(C) Both A and B


(D) None of these



 

Programming C Plus Plus MCQs Homepage

shamil memory table

Computer Science Repeated MCQs Book Download

Exit mobile version