Question: Which of the following statements are true for operator overloading in C++?
A
B
C
D
Operators can be overloaded globally
B
Operators can be overloaded locally
C
Operators can not be overloaded globally
D
none
Note: Not available
#include<stdio.h> int main(int argc, char* argv[]) { enum Colors { red, blue, white = 5, yellow, green, pink }; Colors color = green; printf("%d", color); return 0; }What will be the output when the above code is compiled and executed?
#include<iostream> using namespace std; class myclass { private: int number; public: myclass() { number = 2; } int &a() { return number; } }; int main() { myclass m1,m2; m1.a() = 5; m2.a() = m1.a(); cout << m2.a(); return 0; }
class A { public: A() {} ~A() { cout << "in destructor" << endl; } }; void main() { A a; a.~A(); }How many times will "in destructor" be output when the above code is compiled and executed?
class BaseException { public: virtual void Output() { cout << "Base Exception" << endl; } }; class DerivedException : public BaseException { public: virtual void Output() { cout << "Derived Exception" << endl; } }; void ExceptionTest() { try { throw new DerivedException(); } catch (DerivedException ex) { ex.Output(); } catch (...) { cout << "Unknown Exception Thrown!" << endl; } }Invoking Exception Test will result in which output?
class Shape { public: virtual void draw() = 0; }; class Rectangle: public Shape { public: void draw() { // Code to draw rectangle } //Some more member functions..... }; class Circle : public Shape { public: void draw() { // Code to draw circle } //Some more member functions..... }; int main() { Shape objShape; objShape.draw(); }What happens if the above program is compiled and executed?
class A { public: A():pData(0){} ~A(){} int operator ++() { pData++; cout << "In first "; return pData; } int operator ++(int) { pData++; cout << "In second "; return pData; } private: int pData; }; void main() { A a; cout << a++; cout << ++a; }
#define SQ(a) (a*a) int answer = SQ(2 + 3);What will be the value of answer after the above code executes?