Standard Template Library (STL) Interview Questions & Answers

5 avg. rating (100% score) - 1 votes

Standard Template Library (STL) Interview Questions & Answers

Looking for Standard Template Library (STL) job? Do you have C/C++ Programming experience? Are you expertise in Office API development, MFC, STL, Boost? Then this is the right platform to search and apply jobs as well as preparing for the interview? The C++ STL (Standard Template Library) is a highly standard set of C++ format classes to offer broadly useful classes and functions with layouts that actualize numerous well known and generally utilized calculations and data structures like vectors lists, queues, and stacks. Find the relevant jobs on Standard Template Library (STL) including system operations analyst, developer, and senior embed SW developer, application software engineer, lead/Android security software developer, system analyst, Java developer, windows programmer, sr.administrator wintel etc. Go through wisdom jobs Standard Template Library (STL) job interview questions and answers page for better career opportunities.

Standard Template Library (STL) Interview Questions

Standard Template Library (STL) Interview Questions
    1. Question 1. Write A Program In C++ Returning Starting Locations Of A Sub String Using Pointers?

      Answer :

      #include<stdio.h>

      #include<iostream.h>

      int main()

      {

      Char* mystrstr(char*,char*);

      Char str1[20];

      Char str2[10];

      Cout<<"n Enter two stringst";

      Cin>>str1>>str2;

      Cout<<"nstr1 = "<<str1<<" str2 "<<str2 ;

      Char* c= mystrstr(str1,str2);

      If(c!=NULL)

      printf ("nc = %sn",c);

      Return 0;

      }

      Char* mystrstr(char* str1, char* str2)

      {

      Char *cp = (char *) str1;

      Char *s1, *s2;

      If ( !*str2 )

      return ((char *)str1);

      While (*cp)

      {

      s1 = cp;

      s2 = (char *) str2;

      While ( *s1 && *s2 && !(*s1-*s2) )

      {

      S1++;

      S2++;

      }

      If (!*s2)

      {

      printf ("n string foundn");

      return (cp);

      }

      cp++;

      }

      return(NULL);

      }

    2. Question 2. Write A Program In C/c++ To Implement Reader- Writer Problem?

      Answer :

      Readers-Writers Problem:

      The readers-writers problem is a classic synchronization Problem in which two

      Distinct classes of threads exist, reader and writer. 

      Multiple reader threads can be present in the Database simultaneously. However, the writer threads must have exclusive access. That is, no other writer thread, nor any reader thread, May be present in the Database while a given writer thread is present.

      Note:

      The reader/writer thread must call start Read()/start Write() to enter the database and it must call end Read()/end Write() to exit the database.

      Class Database extends Object {

      Private int numReaders = 0;

      Private int numWriters = 0;

      Private Condition Variable OKtoRead = new Condition Variable ();

      private Condition Variable OKtoWrite = new Condition Variable ();

      public synchronized void start Read() {

      while (numWriters > 0)

      wait(OKtoRead);

      numReaders++;

      }

      public synchronized void end Read() {

      numReaders--;

      notify(OKtoWrite);

      }

      public synchronized void start Write() {

      while (numReaders > 0 || numWriters > 0)

      wait(OKtoWrite);

      numWriters++;

      }

      public synchronized void end Write() {

      numWriters--;

      notify(OKtoWrite);

      notifyAll(OKtoRead);

      }

      }

      class Reader extends Object implements Runnable {

      private Monitor m = null;

      public Reader(Monitor m) {

      this.m = m;

      new Thread(this).start();

      }

      public void run() {

      //do something;

      m.startRead();

      //do some reading…

      m.endRead();

      // do something else for a long time;

      }

      }

      class Writer extends Object implements Runnable {

      private Monitor m = null;

      public Writer(Monitor m) {

      this.m = m;

      new Thread(this).start();

      }

      public void run() {

      //do something;

      m.startWrite();

      //do some writing…

      m.endWrite();

      // do something else for a long time;

      }

      }

      - 2 -

      wait(Condition Variable cond) {

      put the calling thread on the “wait set” of cond;

      release lock;

      Thread.currentThread.suspend();

      acquire lock;

      }

      notify(Condition Variable cond){

      choose t from wait set of cond;

      t.resume();

      }

      notifyAll(Condition Variable cond){

      for all t in wait set of cond;

      t.resume()

      }

      For the following scenarios, we assume that only one reader thread and one writer thread are running on the processor.

    3. Question 3. Explain Method Overloading?

      Answer :

      Method overloading is to overload methods using same class name by writing different parameters. This is called Method overloading.

    4. Question 4. What Is Sorted Linked List?

      Answer :

      Linked list means node which is connected each other with a line. It means that each node is connected with another one. Each node of the list holds the reference of the next node. 

      If we talk about the sorted linked list , it is also a list just like another list. but the difference is only that it hold all the nodes in a sequential manner either in ascending order descending order.

    5. Question 5. What Is The Acronym Of The Term C.o.m.p.u.t.e.r?

      Answer :

      Common operating machine a particular user technical education research. OR

      • C - Conventional
      • O - Organization of
      • M - Man
      • P - Power
      • U - Utilitilised
      • T - Technical
      • E - Enhancement
      • R - Resource.

    6. Question 6. Tell Me About C++?

      Answer :

      c++ is object oriented programming language.. the main  function value should return.

    7. Question 7. How To Get The Sum Of Two Integers?

      Answer :

      #include<stdio.h>

      #include<conio.h>

      void main()

      {

      clrscr();

      int i,j,sum;

      printf("enter two numbers");

      scanf("%d%d",&i,&j);

      sum=i+j;

      printf("sum=%d",sum);

      }

    8. Question 8. Why We Are Using The Fork Command And How It Works?

      Answer :

      In linux fork() system call is used to create a child  process. The Child process inherits some properties of its parent and operates in a separate memory space.

    9. Question 9. Write A C++ Program To Create An Object Of A Class Called Employee Containing The Employee Code Name Designation Basic Salary Hra Da Gross Salary As Data 10 Such Objects "members Process "?

      Answer :

      #include

      #include

      class person

      {

      int person;

      float salary;

      }p;

      cout<<"enter the person name";

      cin>>p.person;

      cout<<"enter the salary";

      cin>>p.salary;

      }

      void main()

      {

      person;

      getch();

      }

    10. Question 10. #define Cube(x) (x*x*x)
      Main()
      { Int A,b=3;
      A=cube(b++);
      Printf("%d %d",a,b);
      }
      What Should Be The Value Of A And B? My Calc A=4 But Syst
      A=6 How Pls Tell Me If You Know It?

      Answer :

      27 4 is the output.

      The call to the macro sets a = b*b*b with b = 3, 3 cubed is 27 then b is incremented to 4 after the macro call.

    11. Question 11. Why & Sign Is Used In Copy Constructor?

      Answer :

      To avoid local copy of object reference (&) is used in copy  constructor. 

      Moreover if the & is omitted then copy constructor goes in  infinite loop.

      eg. if class name is Sample. 

      Copy constructor without &

      Sample :: Sample (Sample s)

      {

      //Code goes here

      }

      and we create object as follows. ;

      Sample s;

      Sample s1(s); 

      In this scenario program will go in infinite loop.

    12. Question 12. Write A C++ To Define A Class Box With Length, Breadth And Height As Data Member And Input Value(), Print Value() And Volume() As Member Functions?

      Answer :

      #include

      #include

      class BOX

      {

      private:

      int l,b,h;

      public:

      void input();

      void print();

      long volume(long,int,int);

      };

      void BOX::input()

      {

      cout<<"input values of l,b,h"<<"n";

      cin>>l>>b>>h;

      }

      void BOX::print()

      {

      out<<"volume="<<"and";

      }

      void BOX::volume()

      {

      long volume(long l,int b,int h);

      {

      return(l*b*h);

      }

      }

      void main()

      {

      set BOX b1;

      b1.input();

      b1.print();

      b1.volume();

      return;

      }

    13. Question 13. Tell Me What Is The Difference Between Thread And Process?

      Answer :

      Thread is a smallest unit of process. In process have one or more thread.

    14. Question 14. What Is The Difference Between C++ And Vc++?

      Answer :

      VC++ uses all C++ features. VC++ has GUI and it is user friendly. It has many programming features like Win32, MFC, ATL, ActiveX, DLLs etc.

    15. Question 15. What Is The Stl?

      Answer :

      It's a sophisticated and powerful library of template classes and template functions that implement many common data structures and algorithms, and forms part of the C++ Standard Library.

    16. Question 16. Who Developed The Stl?

      Answer :

      The STL was developed at Hewlett Packard by Alexander Stepanov, with major contributions by David Musser and Meng Lee. It was deemed by the C++ Standards Committee to be so important to the future of C++ that the approval of the C++ Standard was delayed for several years so that the STL could be incorporated into that Standard. A version of the Standard that incorporated the STL was first approved in the fall of 1998.

    17. Question 17. Why Should A C++ Programmer Be Interested In The Stl?

      Answer :

      Because the STL embodies the concept of reusable software components, and provides off-the-shelf solutions to a wide variety of programming problems. It is also extensible, in the sense that any programmer can write new software (containers and algorithms, for example), that "fit in" to the STL and work with the already-existing parts of the STL, provided the programmer follows the appropriate design guidelines.

    18. Question 18. What Is The Design Philosophy Of The Stl?

      Answer :

      The STL exemplifies generic programming rather than object-oriented programming, and derives its power and flexibility from the use of templates, rather than inheritance and polymorphism. It also avoids new and delete for memory management in favor of allocators for storage allocation and deal location. The STL also provides performance guarantees, i.e., its specification requires that the containers and algorithms be implemented in such a way that a user can be confident of optimal runtime performance independent of the STL implementation being used.

    19. Question 19. What Are The Major Components Of The Stl?

      Answer :

      The containers and container adaptors (both are objects that can hold other objects), the iterators (generalized pointers that point at items in containers), and the algorithms (that work on containers through iterators) will be the most frequently used components of the STL.

    20. Question 20. What Are Some Other Components Of The Stl?

      Answer :

      Other STL components include function objects (objects of a class that defines operator()), or allocators (which manage memory allocation and deal location for containers). Function objects are essential for effective use of the STL, but the average user will be able to ignore allocators most of the time by simply accepting the default allocator for each container used.

    21. Question 21. How Do You Use The Stl?

      Answer :

      By including the necessary header files to permit access to the parts of the STL that you need, by declaring objects of the appropriate container, iterator and function types, and then using member functions and/or algorithms, as appropriate, to perform whatever tasks your application requires. It is also generally necessary to ensure that whatever objects you plan to put into your container(s) are objects of classes that have a default constructor, a copy constructor, and an overloaded operator=. In addition, if you plan to sort or compare such container objects, the corresponding classes must provide definitions for operator== and operator<. Finally, since it is often the case that different containers can be used in the same problem situation, the user needs to be able to make an appropriate choice for each occasion, and this choice will usually be based on performance characteristics.

    22. Question 22. What Are Some Of The Things A Programmer Should Be Aware Of When Using The Stl?(many Of These May Not Make Sense Until You Have Actually Tried To Use The Stl.)

      Answer :

      • Understand member functions size(), max_size() and resize().
      • Understand member functions begin(), end(), rbegin() and rend().
      • Understand the fact that a reference to a "range" of values in STL generally means those values from (and including) the first value in the range up to (but not including) the last value in the range. Such a range can extend forward or backward, depending on the kinds of iterators being used.
      • Even though it may (sometimes) work, it is better not use a loop like for (i = c.begin(); i < c.end(); i++) ... for processing all the elements of a container c; it is preferable instead to use a loop like this: for (i = c.begin(); i != c.end(); i++) ... This second form is often necessary, in fact, since not all container iterators support operator<.
      • RIt is safest to assume that insert() applied to a deque or a vector will invalidate any iterators or references to elements of the deque or vector.
      • Know that any insert() member function applied to a container may (or may not) invalidate iterators and references already pointing at elements of that container.

      In particular:

      1. It is safest to assume that insert() applied to a deque or a vector will invalidate any iterators or references to elements of the deque or vector.
      2. On the other hand, insert() applied to any of the other first-class containers (list, map, multimap, set, multiset) does not invalidate any of the iterators or references to elements of the container, and deletions from these containers invalidate only iterators or references to the elements deleted.
      • Remember that if you are using the STL for a given purpose in a situation that requires (as a minimal requirement) that a certain kind of iterator be used, a more powerful iterator may also be used in that situation
      • Remember that if you have the choice between using an STL algorithm and using an STL container class method to accomplish the same purpose, you should prefer the class method.
      • Know that any container that is the target of an algorithm must be large enough to hold all elements it will receive, since it will not automatically be increased in size. Or, plan to use an inserter.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Design Patterns Tutorial