C++ Questions
C++ Questions
A-/
B - ()
C - ::
D-%
Answer : C
Explaination
#include<iostream>
public:
int i;
abc(int i) {
i = i;
}
};
main() {
abc m(5);
cout<<m.i;
}
A-5
B - Garbage
Answer : B
Explaination
#include<iostream>
using namespace std;
class abc {
public:
int i;
abc(int i) {
i = i;
}
};
main() {
abc m(5);
cout<<m.i;
}
Answer : B
Explaination
Only members of the derived class and the same class can access a protected member.
Answer : A
Explaination
A - Done
B - Compile error
C - Runtime error
Answer : C
Explaination
#include<iostream>
#include<iostream>
cout<<i--;
}
A-0
B - Compile error
C - 65535
D - 32767
Answer : A
Explaination
0, with post decrement operator value of the variable will be considered as the expression’s
value and later gets decremented
#include<iostream>
cout<<i--;
}
#include<iostream>
float y = 5;
r = y%x;
cout<<r;
}
A-1
B-0
C-2
D - Compile error
Answer : D
Explaination
Answer Compile Error, It is invalid that either of the operands for the modulus operator (%) is a real
number.
Answer: c
Explanation: Objects in the method can be accessed using direct member access operator which
is (.).
Ques 10. Which of these following members are not accessed by using direct member access
operator?
a) public
b) private
c) protected
d) both private & protected
Answer: d
Explanation: Because of the access is given to the private and protected, We can’t access them
by using direct member access operator.
Answer: d
Explanation: An Object represents an instance of a class i.e. a variable of that class type having
access to its data members and member functions from outside if allowed.
Answer: d
Explanation: Because a class may contain any number of objects according to its compliance.
Answer: b
Explanation: Operator function means operation defined for that operator so if user defines a
function for an operator then that is called operator overloading i.e. overloading already present
operator function.
Ques 14 Which of the following operators can’t be overloaded?
a) ::
b) +
c) –
d) []
Answer: a
Explanation: :: operator cannot be overloaded because this operator operates on names rather
than values and C++ has no syntax for writing codes that works on names than values so using
syntax these operators cannot be overloaded.
Answer: a
Explanation: We have to declare the operator function by using the operator, operator sign.
Example “operator +” where the operator is a keyword and + is the symbol need to be
overloaded.
Ques 16. Which of the following statements is NOT valid about operator overloading?
a) Only existing operators can be overloaded
b) The overloaded operator must have at least one operand of its class type
c) The overloaded operators follow the syntax rules of the original operator
d) None of the mentioned
Answer: d
Explanation: The overloaded operator must not have at least one operand of its class type.