Microsoft Interview Question






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

1)The members of a structure are public by default, the members of class are private by default.
2)Default inheritance for Structure from another structure or class is public.Default inheritance for class from another structure or class is private.
class A{
public:
int i;
};
class A2:A{
};
struct A3:A{};

struct abc{
int i;
};
struct abc2:abc{
};
class abc3:abc{};

int _tmain(int argc, _TCHAR* argv[])
{
abc2 objabc;
objabc.i = 10;

A3 ob;
ob.i = 10;

//A2 obja; //privately inherited
//obja.i = 10;

//abc3 obss;
//obss.i = 10;
}

This is on VS2005.

- GirishNayak September 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Only the difference is in struct all the data members are defaultly public where as in Class all are data members are private.

- raghava September 11, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Well few more differences.

Classes can be inherited.
The concept of constructor/destructor is not there in structures.

- AD September 14, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Incorrect. As raghava mentioned, structs default to public member access, whereas classes default to private member access. This is the ONLY difference in C++, so you can do anything with a struct that you can do with a class (constructor/destructor, inheritance, operator overloading, etc)

- Anonymous July 09, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Structures support constructor/destructors also...
maybe nor Template programming.

- SunDavid.S September 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

structs do not have member functions to operate on the data members

- anonymous September 18, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

structs can have functions too,its just the default access specifiers that are different between the both

- Anonymous October 26, 2008 | Flag


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