Interview Question for Software Engineer / Developers






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

Well I think constructors are different than functions. We say that constructors even do not return void type therefore if the question is simply returning anything from constructor then the answer is simply a No

- DashDash October 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

I guess the constructor itself does not return anything, we use constructor in conjunction the new keyword and therefore the object instance is returned , if constructor was meant to return something then we could have used it as a function call,its the "new" which creates and returns.

- Gaurav M October 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I will tell you, many people working in the industry believe that "constructor" does return reference to the object", but what I feel that neither it returns nor it requires to return. As per C++ semantics it help creation and initialization of objects through "invocation of constructor by *this object implicitly, thus data members that get initialized belongs to *this object.

- Anonymous October 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As per C++ standards 12.1.12
"No return type (not even void) shall be specified for a constructor. A return statement in the body of a constructor shall not specify a return value. The address of a constructor shall not be taken."

If we put a return statement in a Ctor, it will return from that point. The code below prints only "first"

struct A
{
A()
{
cout<<"first\n";
return;
cout<<"second\n";
}
};

int main()
{
A a;
return 0;
}

- Standards says it returns nothing October 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

No need to research more.... Constructors do not return anything.... That's cent percent correct.... :)

- Geet April 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

if u written obj in constuctor it will always call to that constructor again and again ..but u return *this ok

- prasad March 14, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

If they don't, then "new ABC()" will not return anything. But since it does, yes, constructors return a reference to the newly created object when called.

- Metta October 18, 2010 | 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