ProgrammingModerateProduct-company placement · C++
What is printed?
What is printed?
struct N { int v; N(int x = 7) : v(x) { } };
void show(N n) { cout << n.v; }
int main() {
N a;
N b = 3;
show(4);
show(a);
}- A. 47
- B. 74
- C. 43
- D. 77
Correct answer: A. 47
A constructor whose parameters all have defaults is also the default constructor (a.v = 7), and as a non-explicit single-argument constructor it converts 4 into an N for show.
More OOP with C++ and Java questions
- What is printed? java class P { void f(int x) { System.out.print("P-int "); } } class C extends P { void f(long x) {…
- What is printed? java BigDecimal a = new BigDecimal("1.0"), b = new BigDecimal("1.00"); Set<BigDecimal> h = new HashSet<>(List.of(a, b))…
- What is printed? java Stream.of("a", "bb", "ccc") .filter(s -> { System.out.print("f" + s.length()); return s.length() > 1; }) .map(s -> {…
- What is printed? java Stream.of(1, 2, 3).peek(System.out::print).map(x -> x 2); System.out.print("end");
- What is printed? java Map<Integer, Long> m = Stream.of("a", "bb", "cc", "ddd", "e") .collect(Collectors.groupingBy(String::length…
- What is printed? java Map<Integer, String> m = Stream.of("ab", "cd", "e") .collect(Collectors.toMap(String::length, s -> s))…