ProgrammingHardWipro Elite · TCS NQT Prime
What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std)
What is printed? (C++17; assume <iostream>, <string>, <vector> and using namespace std)
int main() {
vector<int> a(3, 1), b{3, 1};
cout << a.size() << b.size() << b[0];
}- A. 322
- B. 231
- C. 332
- D. 323
Correct answer: D. 323
Parentheses call the (count, value) constructor giving 3 elements; braces prefer the initializer_list giving {3, 1}: sizes 3 and 2, b[0] = 3.
More OOP with C++ and Java questions
- What is printed? java class A { A() { init(); } void init() { System.out.print("A"); } } class B extends A { int v = 5; B() {…
- What is printed? java class S { static { System.out.print("s"); } { System.out.print("i"); } S() { System.out.print("c"); } } // main: new…
- What does this print? java static StringBuilder f() { StringBuilder sb = new StringBuilder("a"); try { sb.append("b"); return sb; }…
- What is printed? java String a = "hi"; String b = new String("hi"); String c = b.intern(); System.out.print((a == b) + " " + (a == c) + "…
- What is printed? java static void f(Integer i) { System.out.print("I"); } static void f(long l) { System.out.print("L"); } static void…
- What is printed? java Integer a = 127, b = 127, c = 128, d = 128; System.out.print((a == b) + " " + (c == d) + " " + c.equals(d));