CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 43
  1. #16
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by Vedam Shashank
    int size need not be the natural data size for given architecture
    In fact it is not on modern 64 bit CPUs/compilers, where sizeof(int) = 4 and sizeof(long) = sizeof(void*) = 8

  2. #17
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by Vedam Shashank
    int size need not be the natural data size for given architecture
    The standard explicitly states that int is intended to have the natural size for the architecture of the target machine.

    3.9.1/2:
    Plain ints have the natural size suggested by the architecture of the execution environment.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  3. #18
    Join Date
    Sep 2004
    Location
    A Planet Called Earth... :-)
    Posts
    835

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by Graham
    The standard explicitly states that int is intended to have the natural size for the architecture of the target machine.
    What do they mean by "natural size" here ????

    I ask this with regard to... this
    C++ program ran... C++ program crashed... C++ programmer quit !!

    Regards

    Shaq

  4. #19
    Join Date
    Sep 2000
    Location
    Indianapolis
    Posts
    6,758

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by Graham
    A company that asks questions like that probably isn't worth working for.
    I disagree.

    I think the amount of discussion generated in this thread indicates that this is an excellent interview question.

    An internview question need not be answerable or correctly worded. After all, in an interview, it isn't the question that is being evaluated, but rather the answer (and the person giving that answer). How someone answers a question is often more important than getting the answer right -- if there even is a correct answer.

    Brad!

  5. #20
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: Ranking from fast to slow .. interview question

    I've had interview questions recently where the correct answer was "undefined behaviour" and they knew it was - they were testing.

  6. #21
    Join Date
    Feb 2006
    Posts
    45

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by Brad Jones
    I disagree.

    I think the amount of discussion generated in this thread indicates that this is an excellent interview question.

    An internview question need not be answerable or correctly worded. After all, in an interview, it isn't the question that is being evaluated, but rather the answer (and the person giving that answer). How someone answers a question is often more important than getting the answer right -- if there even is a correct answer.

    Brad!
    Personally, I'm with Graham on this one, for technical questions at least.

    I've been in interviews where answers to questions like this have become length discussions. In more than a few cases, this has come down to the interviewer setting a question they cannot correctly answer themselves. This question looks very much like one of those. Obviously, until you answer it and talk about it with the interviewer you don't really know for sure.

    Interviews are two way processes: not only is it the employers chance to assess the would-be employee... but also for the employee to assess the would-be employer.

    I've declined and accepted jobs based on whether the person giving a technical interview can knowledgably discuss their own questions. If they can't then it's not a good indicator of the quality of your would-be colleagues.

  7. #22
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: Ranking from fast to slow .. interview question

    It is really unlucky in those times when people ask you something.. you give the correct answer.. but they know the wrong answer themselves and hence rate your correct answer as wrong.

    On one such ocassion - a guy said that the allocation using new in the initializer list (and exception later on generated before exiting from the constructor) is safe. Upon such exceptions the run-time rolls the allocation back. That is the use of initializer list... it is that safe.. I just struck my head and couldn't say a word.. that was an internal one...

    Sorry for the off-topic post.

  8. #23
    Join Date
    Oct 2004
    Posts
    6

    Re: Ranking from fast to slow .. interview question

    I've been in interviews where answers to questions like this have become length discussions. In more than a few cases, this has come down to the interviewer setting a question they cannot correctly answer themselves.

    I would think that would be a reason to keep the question in the interview. If it brings about discussion with the perspective employee. For the very reasons you submitted, if an employee can discuss something with you and you both feel each other is competent (and can communicate with each other) you are more apt to be able to work together. Many companies are looking for that golden mix: a competent programmer who is personable...I tend to take jobs based on what I perceive they can teach me and how I can grow as much as whether I can do what they immediately need me to fulfil.

  9. #24
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by exterminator
    On one such ocassion - a guy said that the allocation using new in the initializer list (and exception later on generated before exiting from the constructor) is safe. Upon such exceptions the run-time rolls the allocation back. That is the use of initializer list... it is that safe..


    Regards,

    Paul McKenzie

  10. #25
    Join Date
    Aug 1999
    Posts
    586

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by Brad Jones
    I disagree.

    I think the amount of discussion generated in this thread indicates that this is an excellent interview question.

    An internview question need not be answerable or correctly worded. After all, in an interview, it isn't the question that is being evaluated, but rather the answer (and the person giving that answer). How someone answers a question is often more important than getting the answer right -- if there even is a correct answer.

    Brad!
    I hope you're right in this case but unfortunately, it's probably an idealistic and optimistic view of the world (with all due respect). The sad truth is that there's rampant incompetence in this field and the inteviewer himself, like most programmers, probably falls into that category (far more often than not anyway).

  11. #26
    Join Date
    Sep 2004
    Location
    A Planet Called Earth... :-)
    Posts
    835

    Re: Ranking from fast to slow .. interview question

    Go daddy could u let us know where (i mean place not which company) did u take the interview, and how many questions were asked in that written round, and how many had to write it along with u????
    C++ program ran... C++ program crashed... C++ programmer quit !!

    Regards

    Shaq

  12. #27
    Join Date
    Feb 2006
    Posts
    69

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by Paul McKenzie
    The correct answer is

    5) None of the above.

    It depends on the compiler's optimizer. That was a trick question.

    Regards,

    Paul McKenzie
    Why would it depend on the compiler optimizer ?

    4 .. is the slowest no ? ....

  13. #28
    Join Date
    Feb 2006
    Posts
    45

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by GoDaddy
    Why would it depend on the compiler optimizer ?

    4 .. is the slowest no ? ....
    Compilers only have to produce a program that works "as if" it were the program you described in the code.

    A "clever" (possibly even too clever!) compiler could optimise this:

    Code:
    for(int i=0;i<16;i++)
      for(int j=0;j<16;j++)
          array1[i]=array2[j];
    to something that looks (algorithmically) like this:

    Code:
    for (int i=0;i<16;i++) array1[i]=array2[15];
    or it could unroll the loop, or dozens of other things. The important thing is that the outcome is "as if" the code being compiled had been run. This could very well wind up being faster than the other examples since there are fewer memory accesses... even though it doesn't do the same thing!

    In practice, many compilers optimisers won't do this (unless it's a trivial case) because they're difficult to spot, and programmers tend not to add loops pointlessly!
    Last edited by Noddon; March 1st, 2006 at 03:19 AM.

  14. #29
    Join Date
    Oct 2005
    Location
    Bangalore
    Posts
    1,051

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by Noddon
    to something that looks (algorithmically) like this:

    for (int i=0;i<16;i++) array1[i]=array2[15];
    - Sreehari
    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
    " Everybody is sent to Earth on a purpose. I am so Lagging behind that i won't die." – Calvin

  15. #30
    Join Date
    Feb 2006
    Posts
    45

    Re: Ranking from fast to slow .. interview question

    Quote Originally Posted by sreehari
    The inner for-loop:

    Code:
    for (j=0;j<16;j++) array1[i]=array2[j];
    has the exact same side effect as:

    Code:
    array1[i]=array2[15];
    since the only assignment to array1[i] which matters is the last one, when j is 15.

Page 2 of 3 FirstFirst 123 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