Here you will find more than 50000 job interview questions

Job Questions Search Engine


Sponsored Links

Different way to initialize vector in STL

September 4, 2010 by bigboss · Leave a Comment
Filed under: C++ Interview Questions 

Vector can be initialized in the different way :

vector v
vector v(3)
vector v(3, 17);
vector v (5, 3.25);

All three are equal :
vector v_new1 (v); // construct v_new1 out of v
vector v_new2 = v; // assign v to vnew2
vector v_new3 (v.begin(), v.end() );

How does dereferencing of Iterator in STL occurs?

September 4, 2010 by bigboss · Leave a Comment
Filed under: C++ Interview Questions 

An iterator has the dereference operator* defined which returns a value of a specific type – the value type of
the iterator ( just like pointer is dereferenced by the expression *pointer ) . Also like a pointer can be incremented by using the operator++, an iterator can be incremented in the same way.

Iterators most often are associated with a container. In that case, the value type of the iterator is the value type of the container and dereferencing the iterator returns an object of this value type.

What are container in STL ? What are the different type of containers

September 4, 2010 by bigboss · Leave a Comment
Filed under: C++ Interview Questions 

In STL .. Container is the class that holds data of other data type. There are two type of container
1. SEQUENCE CONTAINER
2. ASSOCIATIVE CONTAINER

Sequence is a kind of container that organizes a finite set of objects, all of the same type, into a strictly linear
arrangement”. STL provides three basic kinds of Sequence Containers: Vectors, Lists and Deques,
where Deque is an abbreviation for Double Ended Queue.

Associative containers provide an ability for fast retrieval of data based on keys
The elements are sorted and so fast binary search is possible for data retrieval. STL provides four
basic kinds of Associative Containers. If the key value must be unique in the container, this means, if
for each key value only one element can be stored, Set and Map can be used. If more than one element
are to be stored using the same key, Multiset and Multimap are provided

What is an Iterator class ? Difference between Input Iterator and Output Iterator ?

September 3, 2010 by bigboss · Leave a Comment
Filed under: C++ Interview Questions 

A class that is used to traverse through the objects maintained by a container class.

There are five categories of iterators:

Input iterators: An Input Iterator is an iterator that may be dereferenced to refer to some object, and that may be incremented to obtain the next iterator in a sequence. Input Iterators are not required to be mutable.

Output iterators:An Output Iterator is a type that provides a mechanism for storing (but not necessarily accessing) a sequence of values. Output Iterators are in some sense the converse of Input Iterators, but they have a far more restrictive interface: they do not necessarily support member access or equality, and they do not necessarily have either an associated distance type or even a value type . Intuitively, one picture of an Output Iterator is a tape: you can write a value to the current location and you can advance to the next location, but you cannot read values and you cannot back up or rewind.

Forward iterators:Forward Iterators are a refinement of Input Iterators and Output Iterators: they support the Input Iterator and Output Iterator operations and also provide additional functionality. In particular, it is possible to use “multi-pass” algorithms with Forward Iterators. A Forward Iterator may be constant, in which case it is possible to access the object it points to but not to to assign a new value through it, or mutable, in which case it is possible to do both

Bidirectional iterators:Bidirectional Iterators, like Forward Iterators, allow multi-pass algorithms. As the name suggests, they are different in that they support motion in both directions: a Bidirectional Iterator may be incremented to obtain the next element or decremented to obtain the previous element. A Forward Iterator, by contrast, is only required to support forward motion. An iterator used to traverse a singly linked list, for example, would be a Forward Iterator, while an iterator used to traverse a doubly linked list would be a Bidirectional Iterator.

Random access: Random Access Iterators allow the operations of pointer arithmetic: addition of arbitrary offsets, subscripting, subtraction of one iterator from another to find a distance, and so on.

An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class.
The simplest and safest iterators are those that permit read-only access to the contents of a container class.

  • Categories

    |
  • Tags

    ADO.NET Questions Algorithm Questions ASP.NET Questions auto_ptr Binary tree questions C++ Constructor Interview Questions C++ Questions CISCO Exams Questions Common Interview Questions Core Java Interview Questions Csharp Questions datastructure questions Delphi 6 find command gdb interview questions grep interview questions IBM certification exams questions Infosys Puzzles Java Struts Linked List Problem Linux Command Questions List Manager Interview Questions Markov Algorithm memory leakage mysql Interview Questions Normalization Oracle Application Developer Certification Exam Interview Questions Oracle Questions Perl Questions PHP Questions Pointers Interview Questions PostgreSQL Database Questions pthread interview questions Smart Pointer Solaris Interview Questions SQL SERVER Interview Questions STL STL Map Symbian OS Tricky Interview Questions Unix Interview Questions unix shell Vector Windows OS Questions