Question 41
MediumWhat is the output of this program?
#include <iostream>
std;
{
string s = ;
cout << s.(, ) << << s.() << << s.();
;
}
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 s = ;
cout << s.(, ) << << s.() << << s.();
;
}
ace 5 9
acem 5 9
lace 5 9
acem 4 9
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <iostream>
using namespace std;
int main() {
auto add = [](int a, int b) { return a + b; };
int k = 10;
auto addk = [k](int x) { return x + k; };
k = 100;
cout << add(2, 3) << " " << addk(1);
return 0;
}
5 11
5 1
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <iostream>
using namespace std;
int main() {
int x = 10;
auto f = [&x]() { x *= 2; };
f(); f();
cout << x;
return 0;
}
40
20
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main() {
stack<int> s;
queue<int> q;
for (int i = 1; i <= 3; i++) { s.push(i); q.push(i); }
cout << s.top() << q.front() << q.back();
return 0;
}
313
131
Sign up free to see the answer and a step-by-step explanation.
What is the output of this program?
#include <iostream>
using namespace std;
int main() {
int a = 7, b = 2;
cout << a / b << " " << (double)a / b << " " << a % b;
return 0;
}
3 3 1
3.5 3.5 1
Sign up free to see the answer and a step-by-step explanation.
What is the difference between new/delete and malloc/free in C++?
delete does not free memory
malloc is type-safe
new calls constructors and delete calls destructors; malloc/free only manage raw memory
They are identical
Sign up free to see the answer and a step-by-step explanation.
What does std::shared_ptr do when its last copy is destroyed?
Moves the object to a new pointer
Throws an exception
Deletes the managed object
Nothing
Sign up free to see the answer and a step-by-step explanation.
Why can std::unique_ptr not be copied?
It is always null
It is too large
It is a raw pointer
It represents sole ownership; it can only be moved
Sign up free to see the answer and a step-by-step explanation.
Which container gives average O(1) lookup by key in C++?
std::unordered_map
std::map
std::list
std::vector
Sign up free to see the answer and a step-by-step explanation.
What happens to iterators of a std::vector after push_back causes a reallocation?
They are all invalidated
They point to the new elements automatically
Only end() changes
They stay valid
Sign up free to see the answer and a step-by-step explanation.
5 101
Compilation error
80
10
333
311
3 3.5 0
3 3.5 1