- Home
- MCQs by exam
- Campus Interviews
Campus Interviews MCQs · Page 9
346 multiple choice questions typical of the Campus Interviews exam, with answers and explanations. Switch on practice mode to test yourself first.
-
A
Both return the same value after every operation
-
B
capacity counts only elements added with push_back
-
C
size is elements stored; capacity is allocated slots
Correct answer
-
D
size is allocated slots; capacity is elements stored
-
A
One per object, created with each constructor
-
B
One per translation unit that includes the header
-
C
One per derived class that inherits it
-
D
Exactly one, shared by every object of the class
Correct answer
-
A
The function returns a constant value
-
B
The function may only be called once per object
-
C
The object is copied before the call is made
-
D
The function cannot modify the object's members
Correct answer
-
A
It allows overriding functions declared final
-
B
It makes a signature mismatch a compile-time error
Correct answer
-
C
It forces the function to be inlined at call sites
-
D
It makes the base function non-virtual at run time
-
A
Widget(Widget other);
-
B
Widget& operator=(Widget other);
-
C
void Widget(const Widget& other);
-
D
Widget(const Widget& other);
Correct answer
-
A
So delete can free the object without a type check
-
B
So the derived destructor also runs during delete
Correct answer
-
C
So the destructor can be called twice safely
-
D
So the base object is never actually destroyed
-
A
<streambuf>
-
B
<string>
-
C
<iomanip>
-
D
<iostream>
Correct answer
-
A
Immediately after the constructor finishes
-
B
Whenever the object is passed to a function
-
C
When the object lifetime ends, such as scope exit
Correct answer
-
D
Only when the programmer calls delete explicitly on a pointer
-
A
A pointer to the function's own stack frame
-
B
A pointer to the object on which the member was called
Correct answer
-
C
A pointer to the class's static data area
-
D
A reference to the base class subobject of the current object
-
A
A uses-a relationship, where the base is a local variable
-
B
A copies-a relationship, duplicating the base layout
-
C
An is-a relationship, where the derived type specialises the base
Correct answer
-
D
A has-a relationship, where the base object is held as a member of the class
-
A
Inserts an element at the front of the vector
-
B
Replaces the element at the current index position
-
C
Reserves capacity without adding an element
-
D
Appends an element at the end, growing if needed
Correct answer
-
A
A reference to a temporary int value
-
B
A compile error, since new cannot take arguments
-
C
A pointer to a heap int initialised to 5
Correct answer
-
D
An int object with automatic storage duration
-
A
private, unlike struct members which default to public
Correct answer
-
B
public, the same as members of a struct
-
C
protected, so only derived classes and friends may access them
-
D
It depends on whether a constructor is declared
-
A
It converts the arguments to a common base class
-
B
It generates a concrete function for the deduced types
Correct answer
-
C
It boxes the arguments and calls a generic wrapper
-
D
It defers the call until the program is executed
-
A
The precedence of an operator can be redefined
-
B
Overloaded operators are resolved at run time
-
C
At least one operand must be a user-defined type
Correct answer
-
D
Any built-in operator may be given a fresh meaning
-
A
6, because the values are summed
-
B
A compile-time error, since commas are invalid
-
C
3, because the comma yields the last value
Correct answer
-
D
1, because the first value is assigned
-
A
Sets the lowest clear bit of x
-
B
Doubles the value of x
-
C
Reverses the bits of x
-
D
Clears the lowest set bit of x
Correct answer
-
A
3abc, because the inner call's value is buffered first
-
B
abc, with the outer %d printing garbage
-
C
abc3, because printf returns the characters written
Correct answer
-
D
abc0, because the inner call returns nothing
-
A
Restarts the loop from its initial value
-
B
Skips the update expression for that pass only
-
C
Skips the rest of the body and runs the update step
Correct answer
-
D
Exits the loop immediately and continues with the next statement
-
A
It is a compile-time error in every C compiler
-
B
4, because character constants have type int
Correct answer
-
C
1, because a character occupies one byte
-
D
2, because the value fits in a short
-
A
int *(fp(int, int));
-
B
int fp(*)(int, int);
-
C
int (*fp)(int, int);
Correct answer
-
D
int *fp(int, int);
-
A
Opens it read-only until data is written
-
B
Truncates the file to zero length before writing
Correct answer
-
C
Appends new text after the existing content of the file
-
D
Fails and returns NULL to protect the file
-
A
1004, only if p points to an array
-
B
1004, one int further along in memory
Correct answer
-
C
1001, one byte further along in memory
-
D
1000, since the address is unchanged
-
A
8, because padding aligns the int to 4 bytes
Correct answer
-
B
5, the sum of the two member sizes
-
C
4, because the char is packed inside the int
-
D
16, because every struct is 16-byte aligned
-
A
Undefined behaviour, because the literal is read-only
Correct answer
-
B
The literal is modified and prints "Hello"
-
C
A copy on the heap is modified instead
-
D
The compiler automatically allocates writable memory for the literal