CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 4 1234 LastLast
Results 1 to 15 of 52
  1. #1
    Join Date
    Nov 2010
    Posts
    146

    Interview Questions

    Hello All

    Below are the few questions that were asked in an interview. Can anyone please explain to me the answers in an easiest way with examples.

    Code:
    1)	Volatile object
    3)	Can constructor/destructor be private?
    4)	Problems normally faced in multithreading
    6)	Data serialization/de-serialization
    7)	Layers of TCP/IP
    12)	Mutable
    13)	Why do we use virtual destructors?
    14)	what is a copy constructor and why do we use it?
    15)	Smart pointers
    16)	Case where exception handling is not safe
    17)    Static and non-Static member variables/functions
    Thanks
    Last edited by gulHK; August 2nd, 2012 at 09:26 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Interview Questions

    You are not in an interview, and neither are we (presumably). So, make use of the resources at your disposal. You can pretty much search the Web for the answers. The "mutable" one might be hard to find specific stuff on, but if you search it with "C++", you will find the answer.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Interview Questions

    Quote Originally Posted by gulHK View Post
    Below are the few questions that were asked in an interview. Can anyone please explain to me the answers in an easiest way with examples.
    ...
    7) Layers of TCP/IP
    ...
    That is not a C++ question.

    Technically, this isn't a C++ question either:
    4) Problems normally faced in multithreading
    You can be an ace in C++ and not know a single thing about multithreading. I know that many companies will refuse to hire a C++ programmer if their software uses multithreading and the coder has no experience in these types of applications, regardless of how much C++ they know.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; August 2nd, 2012 at 12:01 PM.

  4. #4
    Join Date
    May 2009
    Posts
    2,413

    Re: Interview Questions

    Quote Originally Posted by gulHK View Post
    in an easiest way
    You must understand that your question is rubbing programmers the wrong way. They've spent lots of time and effort learning C++ to get a good job. And here comes some lazy dude who not only knows very little C++ but also has the nerve to ask them to silverspoon him into their company to become their new deadweight collegue. It's not going to happen.

    There are books to prepare you for the interview situation with focus both on C++ and general programming. But in my view for this to work you must already have the knowledge and only need a refresher to summarize and bring things to the top of your head for fast recollection and coherent presentation. If you cram such books you only end up with shallow and superficial knowledge that an experienced interviewer will expose as bull in no time.

    Instead use the flunked interview to identify your weak areas and get the proper books and get down to some serious studying and coding. You're wellcome here if you get stuck with something.
    Last edited by nuzzle; August 4th, 2012 at 01:15 AM.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Interview Questions

    1) volatile is a compiler hint. The correct answer is compiler dependant.
    The fact they are asking this probably means they either don't fully understand the meaning/concept behind it. Or they're trying to trick you into a false/incomplete/incorrect answer. (i.e. ther eis no right answer until they can be more specific)

    6) mostly irrelevant, other than trivial examples and handling plain text. Every other form of (de)serialization is implementation specific.
    Again. See 1). either they have wrong ideas of it, or it's a trick question.

    7) look up "OSI model" on wikipedia.

  6. #6
    Join Date
    Nov 2010
    Posts
    146

    Re: Interview Questions

    Thank you all

    I still have few confusions.

    1) If any of the functions of the base class is virtual then destructor should also be virtual. What will happen if destructor is not virtual?

    2) And I have always found Copy Constructor and copying an object through assignment operator. Will you please explain to me what are these and in what situations are these used? When to use which one? Please with an example

    Thanks

  7. #7
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Interview Questions

    Quote Originally Posted by gulHK
    1) If any of the functions of the base class is virtual then destructor should also be virtual. What will happen if destructor is not virtual?
    If you attempt to delete an object of a derived class through a base class pointer that points to it, and the base class destructor is not virtual, then the behaviour is undefined.

    Quote Originally Posted by gulHK
    2) And I have always found Copy Constructor and copying an object through assignment operator. Will you please explain to me what are these and in what situations are these used? When to use which one? Please with an example
    I shall not explain with an example. Rather, I shall explain with a book: Accelerated C++.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  8. #8
    Join Date
    Nov 2010
    Posts
    146

    Re: Interview Questions

    Thanks laserlight . Virtual destructor concept is now clear to me

  9. #9
    Join Date
    Nov 2010
    Posts
    146

    Re: Interview Questions

    I have now gone through few of the websites to clear my concepts about copy constructor and assignment and have found out that these are just two different ways that serve the same purpose, one through copy constructor and one through assignment. Then why are there two different ways when one will do? Please correct me if I am wrong.

  10. #10
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Interview Questions

    Quote Originally Posted by gulHK View Post
    I have now gone through few of the websites to clear my concepts about copy constructor and assignment and have found out that these are just two different ways that serve the same purpose
    Is that what these "websites" taught you? Then it's time to get a book.
    Code:
    class foo
    {
    };
    
    int main()
    {
        foo f;
        foo f2 = f;
        foo f3(f2);
        foo f4;
        f4 = f;
    }
    So after going through these "websites" as you claimed, you should know which lines of code invoke the copy constructor of foo and which ones invoke the assignment operator, right?

    There is a big difference in the two -- the copy constructor constructs a new object, while the assignment operator assigns to an existing object. That's why one is called a constructor and the other one is called assignment.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; August 5th, 2012 at 10:26 AM.

  11. #11
    Join Date
    Nov 2010
    Posts
    146

    Re: Interview Questions

    Paul I know which one uses copy constructor and which one uses assignment but what are the uses of each of these two ways? why not we just always use a copy constructor or why not always an assignment? Are there certain situations where copy constructor works best or where assignment works best. Does the usage depend on any situation?

  12. #12
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Interview Questions

    Quote Originally Posted by gulHK
    I know which one uses copy constructor and which one uses assignment but what are the uses of each of these two ways?
    Please answer these questions:
    • Which of them use the copy constructor and which of them uses the copy assignment operator?
    • What is the difference between constructing an object and assigning to it?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  13. #13
    Join Date
    Nov 2010
    Posts
    146

    Re: Interview Questions

    That's what's written in one of the websites

    Code:
    Cents cMark(5); // calls Cents constructor
    Cents cNancy; // calls Cents default constructor
    cNancy = cMark; // calls Cents assignment operator
    
    
    Cents cMark(5); // calls Cents constructor
    Cents cNancy = cMark; // calls Cents copy constructor!

  14. #14
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Interview Questions

    Quote Originally Posted by gulHK View Post
    Paul I know which one uses copy constructor and which one uses assignment
    OK, so tell us -- which ones invoke the copy constructor and which ones invoke the assignment operator?
    why not we just always use a copy constructor or why not always an assignment?
    I already stated it to you:

    A copy constructor constructs a brand new object from an existing object. An assignment object takes an existing object and turns it into a copy of another object. It can't be explained more simply than that.

    Regards,

    Paul McKenzie

  15. #15
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Interview Questions

    Quote Originally Posted by gulHK View Post
    That's what's written in one of the websites

    Code:
    Cents cMark(5); // calls Cents constructor
    Cents cNancy; // calls Cents default constructor
    cNancy = cMark; // calls Cents assignment operator
    
    
    Cents cMark(5); // calls Cents constructor
    Cents cNancy = cMark; // calls Cents copy constructor!
    So what's the question?

    Regards,

    Paul McKenzie

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured