Visit our sponsor Granny's Eggs  
Home
Microsoft Interview Process
HR Questions
Technical Questions
Puzzles/Riddles
Resume Tips and Template
Discuss
Question to Interviewer
Interview Tips
Term Of Use
Site Feedback


Implement and test a memcpy function
The function copies memory block pointed by src into memory block pointed by dst. 1. Request the types of arguments and return value (thus determing the real declaration: void memcpy( void* src, void* dst, size_t size ); 2. Request the units of size. 3. Mention the case of overlapping src and dst blocks. Be very careful about this case. void memcpy( void* src, void* dst, size_t size ) { char *pc_src = src, *pc_dst = dst; //in C++ this will require an explicit cast if(pc_dst <= p_src ) for( char* it_src = pc_src, *it_dst = pc_dst; it_src < pc_src + size_t; it_src++, it_dst++ ) *it_dst = *it_src; else for( char* it_src = pc_src + size-1, *it_dst = pc_dst + size-1; it_src >= pc_src; it_src--, it_dst-- ) *it_dst = *it_src; } Now I'm too lazy to write the tests, but do mention the cases: 1. A usual case. Also check that the memory around src and dst doesn't change. 2. A case of overlapping blocks: src before and beyond dst. Also src and dst at the same address. 3. size = 1 and size = 0 cases. 4. You may be asked to write a case when memory is copied between different data types (e.g. unsidned int and char[4])

 

Add Your Comment

New Articles
  • Program the Fib Sequence without recursion

  • Everyone learns how to do recursion with the Fibonacci sequence in Programming 101. Do it programmatically without recursion.

  • Implement and test a memcpy function
    Given a function header (in fact an out-of context function call):
    memcpy(src, dst, size)
    Write an implementation and test cases.
    Be sure to ask additional questions on what exactly the function does and the range of arguments as well.



  • Implement an allocator
    Implement a memory allocator, i.e. malloc function, free function and all data structures, needed for that.

  •  

    Most Popular Articles
  • Crazy Guy On The Airplane

  • A line of 100 airline passengers is waiting to board a plane. they each hold a ticket to one of the 100 seats on that flight.

  • Question: Tell me about yourself.
    Many candidates, unprepared for the question, skewer themselves by rambling, recapping their life story, delving into ancient work history or personal matters.

  • What are your greatest weaknesses
    Beware - this is an eliminator question, designed to shorten the candidate list. Any admission of a weakness or fault will earn you an “A” for honesty, but an “F” for the interview.

  •  




  •