Question 71
HardWhat is the output of this program?
#include <iostream>
#
std;
{
string a = , b = ;
cout << (a < b) << (a.(b) < ) << (a + b).(, );
;
}
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Programming Languages
What is the output of this program?
#include <iostream>
#
std;
{
string a = , b = ;
cout << (a < b) << (a.(b) < ) << (a + b).(, );
;
}
01cab
10cab
11abd
11cab
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
int arr[] = {5, 2, 8, 1};
sort(arr, arr + 4, [](int x, int y) { return x > y; });
cout << arr[0] << arr[3] << accumulate(arr, arr + 4, 0);
return 0;
}
8116
5116
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <iostream>
#include <set>
#include <iterator>
using namespace std;
int main() {
set<int> s{5, 1, 9, 3};
auto it = s.upper_bound(3);
cout << *it << " " << distance(s.begin(), it) << " " << s.count(4);
return 0;
}
3 1 0
5 3 0
Sign up free to see the answer and a step-by-step explanation.
What does std::move do to a std::string that is then left unused?
It casts it to an rvalue so its buffer can be moved; the source is left valid but unspecified (usually empty)
It deletes the string
It makes the string constant
It copies the string
Sign up free to see the answer and a step-by-step explanation.
Why is passing large objects as 'const T&' common in C++?
It makes the object global
It is required for templates
It forces a copy
It avoids copying while promising not to modify the argument
Sign up free to see the answer and a step-by-step explanation.
What is undefined behaviour in C++?
Code whose result the standard doesn't define, such as reading past an array's end; the compiler may assume it never happens
A compile error
Behaviour that depends on the operating system
A runtime exception
Sign up free to see the answer and a step-by-step explanation.
What does constexpr on a function mean?
It can be evaluated at compile time when given constant arguments
It is always inlined
It runs on the GPU
It can't be called
Sign up free to see the answer and a step-by-step explanation.
What is the difference between std::array and std::vector?
They are identical
std::array is slower
std::vector can't hold ints
std::array has a fixed size known at compile time; std::vector can grow at run time
Sign up free to see the answer and a step-by-step explanation.
When does iterator invalidation happen with std::vector?
Never
Only when the vector is destroyed
When an insertion causes reallocation, or for elements at or after an erased position
On every read
Sign up free to see the answer and a step-by-step explanation.
What is the purpose of the 'override' and 'final' specifiers?
override checks that a function really overrides a virtual one; final stops further overriding or inheritance
They make functions static
They are comments
They make functions faster
Sign up free to see the answer and a step-by-step explanation.
8115
1816
9 2 1
5 2 0