Basic C++ interview questions

1.Question: Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321].
Answer: quicksort ((data + 222), 100);

2.Question: Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?
Answer: Mergesort always makes recursive calls to sort subarrays that are about half size of the original array, resulting in O(n log n) time.

3.Question: What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator.
Answer: .An internal iterator is implemented with member functions of the class that has items to step through. .An external iterator is implemented as a separate class that can be "attach" to the object that has items to step through. .An external iterator has the advantage that many difference iterators can be active simultaneously on the same object.

4.Question: Why are arrays usually processed with for loop?
Answer: The real power of arrays comes from their facility of using an index variable to traverse the array, accessing each element with the same expression a[i]. All the is needed to make this work is a iterated statement in which the variable i serves as a counter, incrementing from 0 to a.length -1. That is exactly what a loop does.

5.Question: What is an HTML tag?
Answer: An HTML tag is a syntactical construct in the HTML language that abbreviates specific instructions to be executed when the HTML script is loaded into a Web browser. It is like a method in Java, a function in C++, a procedure in Pascal, or a subroutine in FORTRAN.

This entry was posted in C++. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments on Basic C++ interview questions

  1. John Swan
    Posted 3/24/2004 at 5:23 pm | Permalink

    An interesting read.
    Not quite C++ questions though. Granted valid code but with regards to loops and arrays. I would work off containers and iterators. The real powers of C++. These questions are more ‘C’ orientated. Bloody nice questions though :)

  2. Charles
    Posted 10/9/2006 at 9:06 pm | Permalink

    quicksort((data + 222 * sizeof(int)), 100)
    OR
    quicksort(&data[222], 100)

    data + 222 will go 222 memory locations past. For example if data is 1000 (assuming decimal representation), data+222 would be 1222. However, we want to go 222*4 (assuming 32 bit system) to go 222 numbers further.

  3. Ravi Sankar
    Posted 12/19/2007 at 2:01 pm | Permalink

    data + 222 will not go 222 memory locations past. Since data is an array of integers, “data + 222″ will be calculated as “data + 222*(sizeof(int)” internally. And so, quicksort(data + 222, 100) is right and quicksort(data +222*(sizeof(int)), 100) is wrong.

    Suppose data is pointing to memory location 1000, “data+222*(sizeof(int))” will go to (1000+222*4*4) = 4552 (taking int size as 4 bytes).

2 Trackbacks

  1. By pharmacy on 6/10/2005 at 8:59 pm

    pharmacy

    You can also check the sites about prescription drugs skin care products

  2. [...] Tools related 1. C++ a. TechInterviews.com b. SoftCorp c. mac.com d. Hot Interview Questions - Arindham Chakrabarti e. Bjarne Stroustrups C++ FAQ [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*