quiz-8-essen.docx - What is the output of the following...

This preview shows page 1 - 4 out of 8 pages.

What is the output of the following program? #include <iostream> using namespace std; class A { public: int v; A():v(1) {} A(int i):v(i) {} void operator<<(int a) { v+=a; } }; int main(void) { A i = 2; i << 2; cout << i.v << endl; return 0; } 1 4 The program will cause a compilation error. 2 Question 2 1 / 1 pts What is the output of the following program? #include <iostream> using namespace std; class A { public: int v; A():v(1) {}
A(int i):v(i) {} void operator<<(int a) { v>>=1; } }; ostream& operator<<(ostream &o, A &a) { return o<<a.v; } int main(void) { A i = 2; i << 2; cout << i << endl; return 0; } 4 2 1 The program will cause a compilation error. Question 3 1 / 1 pts What is the output of the following program? #include <iostream> using namespace std; class A { public: int v; A():v(1) {} A(int i):v(i) {} void operator&&(int a) { v = -v; } }; int main(void) { A i = 2;
i && 2; cout << i << endl; return 0; } 1 The program will cause a compilation error. 4 2 Question 4 1 / 1 pts What is the output of the following program? #include <iostream> using namespace std; enum e { a,b,c,d }; int main(void) { e f = e(a + c); cout << f << endl; return 0; } The program will cause a compilation error (or warning in some compilers), 2

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture