Recent Yahoo Interview Questions - May be Helpful


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Recent Yahoo Interview Questions - May be Helpful

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    1

    Thumbs up Recent Yahoo Interview Questions - May be Helpful

    Folks,

    I am an experienced developer and happend to attend the interview at yahoo India development centre.

    The pity part is interviewers are coming with print outs of programs written on paper. So, It is often possible you can easily overlook some of the things on the paper. But that is the fact and be prepared...

    Here we go:

    Question 1:
    ========

    class A()
    {
    A() : { func(); }

    virtual void func() { cout << "in A " << endl; }
    }

    class B()
    {

    B();

    virtual void func() { cout << "in B" << endl; }

    }

    main()
    {
    B b;
    }

    Question: What will be printed();

    Question 2: (is there any problems with following programs?)

    NOTE:- there may be mistake in my typing, but you can assume
    that functions are correct.

    =========

    string& getAccount()
    {
    string str(15);
    return str;
    }

    int getVectValue(int key, vector<string> vect)
    {
    int value = vect.getvalue(key);
    return val;
    }

    string getStringValue(int size)
    {
    string tempstr[size];
    switch(size)
    {
    case 1:
    strcpy(tempstr, "ONE");
    case 2:
    strcpy(tempstr,"TWO");
    }
    return tempstr;
    }

    Question 3:
    =========

    I was asked to implement auto_ptr equivalent with templates.
    There are several Smart Pointer classes out there, you can refer them

    Question 4:
    =========

    I was asked to write a singleton pattern program. There was a lot of discussion went in around this.

    Question 5:
    ===========

    One guy asked me following question.

    Can you implement garbage collector in C++ and how you do that?

    It may be possible, but to be honest, if some body can do this, it would have
    been already available. May that is the research they are doing.

    Question 6:
    ==========

    There was a discussion around how a unix program will be invoked and executed from shell.

    I hope this give some insights into questions they are asking.

    But beware, if they are honest about your recruitment, you will surely be asked what you are supposed to do as part of your job.

    In my case, since they are asking about Garbage Collector in C++...well... by now, you know the outcome of interview .....


    - Jason2010

  2. #2
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Code:
    string& getAccount()
    {
    string str(15);
    return str;      // returning a reference to a local variable - it's undefined when the function exits
    }
    
    int getVectValue(int key, vector<string> vect)
    {
    int value = vect.getvalue(key);  // vectors aren't maps and don't have a "value"
    return val;
    }
    
    string getStringValue(int size)
    {
    string tempstr[size]; // creating an array of strings of length size (using the default constructor) (not what's intended)
    switch(size)
    {
    case 1:
    strcpy(tempstr, "ONE"); // just plain wrong with an array
    case 2:
    strcpy(tempstr,"TWO"); // ditto
    } 
    return tempstr;
    }
    Hi, I'm pretty new to C++, but I thought I'd have a gander. Any good?

    Also, no idea about this:
    Code:
    class B()
    {
    
    B(); // don't you need an implementation for this constuctor?
    
    virtual void func() { cout << "in B" << endl; }
    
    }
    Also, all i can say is that "in B" is printed. Is that even close?

  3. #3
    Join Date
    May 2004
    Posts
    40
    Also, all i can say is that "in B" is printed. Is that even close?
    I think, since there is no implementation of the B constructor, that as written nothing would be printed (nothing calls either func method).

    I'm not sure if there is a transcription error here, this resembles a classic interview question that usually relies on B being a child of A.Or maybe they want you to think that's what they're asking about.

    Question 5:
    ===========

    One guy asked me following question.

    Can you implement garbage collector in C++ and how you do that?

    It may be possible, but to be honest, if some body can do this, it would have
    been already available. May that is the research they are doing.
    Answer: I'm a developer. Give me enough time and of course I can. It would probably involve rewriting the compiler or mandatory inclusion of some library (or both), and would be non-standard, but I could do it. 8o)
    Last edited by ajhampson; 04-27-2010 at 10:29 AM. Reason: clarification

  4. #4
    Join Date
    Oct 2007
    Posts
    369
    Some environments already come with a garbage collector. You don't have to rewrite the compiler. Use a "smart pointer" template and placement new. I've never done it, but it can be done in native C++.

  5. #5
    Join Date
    Dec 2003
    Posts
    3,366
    Smart pointers and the like put the burden on the programmer though. At that point, its not GC, its a style guideline that greatly reduces the chance for pointer goofs/leaks/etc. IE a programmer can grab the code, hack in an "int *fubar = new int[1000000]; fubar = 0;" and ruin everything with just 2 lines of code, and there is no way (in the raw language) to handle this sort of problem, whether its from legacy code, opensource, programmer @ 2am, or whatever reason that gets it into the code. Once the style is violated, and just one programmer drops the ball, the GC of the whole system is compromised.


    I don't think GC can be added to the language by a user of the language in any reliable fashion (apart from writing a nonstandard compiler). Code can be written to handle memory safely (but you can do that with raw pointers too) and tools exist to warn programmers about potentially problematic code and all that, yes. But to enforce GC upon joe-freshman@college using the full (not reduced subset of) c++ language any way he wants to using standard compilers, it cannot be done.

  6. #6
    Join Date
    May 2012
    Posts
    1
    Hi,

    Thanks very much for this comment. It help me to think about my ideals.

    Tks again and pls keep posting.

Similar Threads

  1. 400 + Java Interview Questions
    By pravin007 in forum Java
    Replies: 4
    Last Post: 05-07-2013, 04:48 AM
  2. Replies: 0
    Last Post: 12-16-2006, 02:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center