Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

New copies of Object would be created. Only in case of pointers the same object would be referred as only the pointer variable copy would be created.

- Som April 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It depends on the type of container. Some of them allow duplicate keys others donot.

Map does not allow duplicate keys.
So A is the key(not the val to be stored):
map<A, val1> and map<A, val2> would end in val2 being stored

If A is the value(not the key), then
map<key1, A> and map<key2, A> would result in two separate copies of A being stored in two separate places

Multimap, allows storage of duplicate keys.

- puneet.sohi April 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes, it's always copies. Keep in mind, however, that nothing is stopping you from using some pointer type for A, in which case you'd be making a copy of the pointers and not the objects themselves. Having some type like vector<int*> is perfectly valid.

- eugene.yarovoi April 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Depends on the data structure and the type of object that is being copied has a default copy operator. i believe the question is, will a deep copy be performed or a reference.

- ntf January 06, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More