Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical

    Interview Question of the Day (IQOD) #1

    I like Why06's idea of the 'error of the day' so I figured i'd post some of the questions I have asked people while interviewing them for C++ Software Developer Positions.

    These questions are usually written on a whiteboard (or printed out) and thus are meant to be answered WITHOUT the help of a compiler in an interview! So just read the code, don't copy/paste/build/run and just figure out what it does by reading.

    I suggest you answer in a 'white font' so that others don't immediately see your answers


    IQOD #1:
    Consider the following program snippet:
    Code:
    #define   ABC    20
    #define   XYZ    10
    #define   XXX    ABC-XYZ
    
    void main()
    {
           int a;
           a = XXX * 10;
           printf("%d\n",a);
    }
    Question: What output is generated / is the value of 'a'?
    Last edited by B1ackAnge1; 09-17-2009 at 07:10 PM.

  2. #2
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Hmmmm... ok. Seems pretty easy. My Guess: 100

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  3. The Following User Says Thank You to why06 For This Useful Post:

    B1ackAnge1 (09-18-2009)

  4. #3
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical
    And you sir would be: Incorrect

  5. #4
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Thanks a lot for these Black Angel =D

    My guess: 100
    But: I'm not sure whether or not you should have put the abc-xxx in brackets hmm actually nvm
    Last edited by zeco; 09-17-2009 at 07:54 PM.

  6. #5
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical
    You guys want the full answer with explanation now or tomorrow so the other guys can chime in? I can just write it in white I guess?

  7. #6
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Quote Originally Posted by B1ackAnge1 View Post
    You guys want the full answer with explanation now or tomorrow so the other guys can chime in? I can just write it in white I guess?
    Write it in white please, i will check after i think i know the answer again.

    Oh... I GET IT NOW xD. That was a very skillful question. Kudos.

    Still kudos, but i don't get it anymore xD.

    Grr. I did infact get it, but i'm stupid.
    Last edited by zeco; 09-17-2009 at 08:05 PM.

  8. The Following User Says Thank You to zeco For This Useful Post:

    B1ackAnge1 (09-18-2009)

  9. #7
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Woops double post >_<

  10. #8
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical
    Highlight Post to see answer & explanation below
    -----------------------------------------------
    The Answer is: -80

    #define works like a 'Find & Replace' before the program gets compiled ,thus the program actually sees:
    Code:
    #define   ABC    20
    #define   XYZ    10
    #define   XXX    20-10
    
    void main()
    {
           int a;
          // a = XXX * 10; This is then seen as:
          a = 20 - 10 * 10;
           printf("%d\n",a);
    }
    Following the standard operator order the multiplication gets performed first so you end up with 20-100 = 80;

    Zeco got close by mentioning the brackets. Had we wanted to output 100 instead then placing brackets in the definition of XXX would've taken care of that: #define XXX (20-10); a = (20-10) * 10; etc

  11. #9
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    This is why i fail and am stupid.

    When i previously said i got it, i had the same solution as Black angel. Then a little thing in my brain said. Are you stupid, - and * have the same operator precendence(importantness thingy). Even though i do know that * goes before -. I need to like sterilize my brain. grrr.

    But now i am really anticipating your next one. These are really cool. I have to wait an entire 12-24 hours T_T.
    Last edited by zeco; 09-17-2009 at 08:06 PM.

  12. #10
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    OK. Before I see the answer last Guess: 200 or there something up with the #define statements

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  13. #11
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Quote Originally Posted by why06 View Post
    OK. Before I see the answer last Guess: 200 or there something up with the #define statements
    Why06, your answer is: Incorrect

  14. #12
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Yeh. I noticed that. I have no idea how #define works, but now I do. That's actually pretty neat, but I guess since i failed I don't get the job xD.


    Quote Originally Posted by zeco View Post
    This is why i fail and am stupid.

    When i previously said i got it, i had the same solution as Black angel. Then a little thing in my brain said. Are you stupid, - and * have the same operator precendence(importantness thingy). Even though i do know that * goes before -. I need to like sterilize my brain. grrr.

    But now i am really anticipating your next one. These are really cool. I have to wait an entire 12-24 hours T_T.
    Zeco you gotta lighten up. Your harder on urself then anyone else. I would tell you to stop calling urself stupid, but I'm not sure what weird side affect that might have with your split personality and all? o_O

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  15. #13
    zeco's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    Canada
    Posts
    683
    Reputation
    12
    Thanks
    78
    My Mood
    Cynical
    Quote Originally Posted by why06 View Post
    Yeh. I noticed that. I have no idea how #define works, but now I do. That's actually pretty neat, but I guess since i failed I don't get the job xD.



    Zeco you gotta lighten up. Your harder on urself then anyone else. I would tell you to stop calling urself stupid, but I'm not sure what weird side affect that might have with your split personality and all? o_O
    Huh 0.0 What split personality was this again? >_< I am quite forgetful xD.

    BlackAnge1, how many chances do you usually give a candidate to answer correctly? And do they have Pen and paper to work with? I'm just curious =D.
    Last edited by zeco; 09-17-2009 at 10:05 PM.

  16. #14
    B1ackAnge1's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    455
    Reputation
    74
    Thanks
    344
    My Mood
    Cynical
    Quote Originally Posted by zeco View Post
    BlackAnge1, how many chances do you usually give a candidate to answer correctly? And do they have Pen and paper to work with? I'm just curious =D.
    Usually they get to work on the whiteboard with a dry-erase marker. Depending on the problem I'd talk them through it if they get it wrong: "Are you sure?" give them a hint and see if they get it depending on how well they're doing.

    Other times I may just move on and mark them as wrong if it's a simple problem.
    If you're interviewing for a C++ position but don't know the difference between i++ and ++i then that says it all right there

  17. #15
    lalakijilp's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Posts
    310
    Reputation
    9
    Thanks
    53
    My Mood
    Blah
    20 -10*10 = 20 -100 = -80 <--answer

    owned

    why don't u guys put all these questions together so other people can try them to?

  18. The Following User Says Thank You to lalakijilp For This Useful Post:

    B1ackAnge1 (09-18-2009)

Page 1 of 2 12 LastLast

Similar Threads

  1. Word/Phrase of the day!
    By Dave84311 in forum General
    Replies: 77
    Last Post: 01-11-2009, 02:37 PM
  2. GenX New Hack By End Of The Day
    By GenX in forum WarRock - International Hacks
    Replies: 42
    Last Post: 07-21-2008, 08:28 PM
  3. Riddle Of The Day!
    By Snipified4 in forum General
    Replies: 22
    Last Post: 05-22-2008, 08:39 AM
  4. Question to the opposite sex!
    By nukeist_ in forum Spammers Corner
    Replies: 6
    Last Post: 01-15-2008, 10:24 AM

Tags for this Thread