Top 100+ Standard Template Library (stl) Interview Questions And Answers
Question 1. Write A Program In C++ Returning Starting Locations Of A Sub String Using Pointers?
Answer :
#encompass<stdio.H>
#encompass<iostream.H>
int most important()
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);
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 > zero)
wait(OKtoRead);
numReaders++;
public synchronized void quit Read()
numReaders--;
notify(OKtoWrite);
public synchronized void begin Write()
whilst (numReaders > 0 numWriters > zero)
wait(OKtoWrite);
numWriters++;
public synchronized void cease Write()
numWriters--;
notify(OKtoWrite);
notifyAll(OKtoRead);
elegance Reader extends Object implements Runnable
personal Monitor m = null;
public Reader(Monitor m)
this.M = m;
new Thread(this).Begin();
public void run()
//do something;
m.StartRead();
//do a little studying…
m.EndRead();
// do something else for a long time;
class Writer extends Object implements Runnable
personal Monitor m = null;
public Writer(Monitor m)
this.M = m;
new Thread(this).Begin();
public void run()
//do something;
m.StartWrite();
//perform a little writing…
m.EndWrite();
// do some thing else for a long term;
- 2 -
wait(Condition Variable cond)
placed the calling thread at the “wait set” of cond;
release lock;
Thread.CurrentThread.Suspend();
gather lock;
notify(Condition Variable cond)
pick out 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 expect that only one reader thread and one author thread are running on the processor.
UML Interview Questions
Question 3. Explain Method Overloading?
Answer :
Method overloading is to overload techniques using identical class name by way of writing one of a kind parameters. This is called Method overloading.
Question four. What Is Sorted Linked List?
Answer :
Linked list means node which is connected every other with a line. It method that every node is hooked up with any other one. Each node of the list holds the reference of the subsequent node.
If we talk approximately the taken care of linked list , it is also a listing just like every other listing. But the distinction is best that it keep all of the nodes in a sequential way both in ascending order descending order.
UML Tutorial
Question five. What Is The Acronym Of The Term C.O.M.P.U.T.E.R?
Answer :
Common running system a particular person technical education research. OR
C - Conventional
O - Organization of
M - Man
P - Power
U - Utilitilised
T - Technical
E - Enhancement
R - Resource.
Python Interview Questions
Question 6. Tell Me About C++?
Answer :
c++ is item oriented programming language.. The main characteristic value must return.
Question 7. How To Get The Sum Of Two Integers?
Answer :
#consist of<stdio.H>
#consist of<conio.H>
void major()
clrscr();
int i,j,sum;
printf("enter two numbers");
scanf("%dp.Cd",&i,&j);
sum=i+j;
printf("sum=%d",sum);
Python Tutorial Java-Multithreading Interview Questions
Question 8. Why We Are Using The Fork Command And How It Works?
Answer :
In linux fork() machine name is used to create a child process. The Child method inherits a few homes of its figure and operates in a separate memory space.
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 "contributors Process "?
Answer :
#include
#include
elegance individual
int individual;
go with the flow revenue;
p;
cout<<"enter the person name";
cin>>p.Person;
cout<<"enter the salary";
cin>>p.Salary;
void fundamental()
man or woman;
getch();
Java Design Patterns Interview Questions
Question 10. #outline 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=four But Syst
A=6 How Pls Tell Me If You Know It?
Answer :
27 4 is the output.
The name to the macro sets a = b*b*b with b = three, 3 cubed is 27 then b is incremented to 4 after the macro name.
Adaptive software program improvement Tutorial
Question eleven. Why & Sign Is Used In Copy Constructor?
Answer :
To keep away from local copy of object reference (&) is utilized in copy constructor.
Moreover if the & is ignored then copy constructor goes in infinite loop.
Eg. If class call is Sample.
Copy constructor without &
Sample :: Sample (Sample s)
//Code goes right here
and we create item as follows. ;
Sample s;
Sample s1(s);
In this scenario software will go in countless loop.
Socket Programming Interview Questions
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
magnificence BOX
private:
int l,b,h;
public:
void enter();
void print();
long volume(long,int,int);
;
void BOX::input()
cout<<"enter values of l,b,h"<<"n";
cin>>l>>b>>h;
void BOX::print()
out<<"quantity="<<"and";
void BOX::volume()
lengthy volume(long l,int b,int h);
go back(l*b*h);
void predominant()
set BOX b1;
b1.Enter();
b1.Print();
b1.Extent();
return;
UML Interview Questions
Question 13. Tell Me What Is The Difference Between Thread And Process?
Answer :
Thread is a smallest unit of procedure. In technique have one or extra thread.
Question 14. What Is The Difference Between C++ And Vc++?
Answer :
VC++ uses all C++ features. VC++ has GUI and it's miles consumer pleasant. It has many programming capabilities like Win32, MFC, ATL, ActiveX, DLLs etc.
Question 15. What Is The Stl?
Answer :
It's a sophisticated and effective library of template instructions and template capabilities that enforce many not unusual facts structures and algorithms, and bureaucracy a part of the C++ Standard Library.
Unix Inter-Process Communication (IPC) Interview Questions
Question sixteen. Who Developed The Stl?
Answer :
The STL became developed at Hewlett Packard by using Alexander Stepanov, with important contributions through David Musser and Meng Lee. It changed into deemed by using the C++ Standards Committee to be so important to the future of C++ that the approval of the C++ Standard changed into behind schedule for several years so that the STL might be included into that Standard. A model of the Standard that incorporated the STL became first accepted inside the fall of 1998.
Question 17. Why Should A C++ Programmer Be Interested In The Stl?
Answer :
Because the STL embodies the concept of reusable software program components, and affords off-the-shelf solutions to a wide type of programming issues. It is also extensible, in the sense that any programmer can write new software program (containers and algorithms, for instance), that "in shape in" to the STL and paintings with the already-current elements of the STL, furnished the programmer follows the appropriate design hints.
Algorithm Interview Questions
Question 18. What Is The Design Philosophy Of The Stl?
Answer :
The STL exemplifies typical programming instead of object-oriented programming, and derives its strength and flexibility from using templates, in place of inheritance and polymorphism. It also avoids new and delete for memory control in desire of allocators for storage allocation and deal vicinity. The STL additionally offers performance guarantees, i.E., its specification calls for that the containers and algorithms be implemented in this sort of manner that a user may be confident of most advantageous runtime performance unbiased of the STL implementation being used.
Python Interview Questions
Question 19. What Are The Major Components Of The Stl?
Answer :
The packing containers and container adaptors (both are gadgets which could keep other objects), the iterators (generalized guidelines that point at gadgets in containers), and the algorithms (that paintings on bins through iterators) will be the most regularly used components of the STL.
Question 20. What Are Some Other Components Of The Stl?
Answer :
Other STL components include characteristic items (items of a class that defines operator()), or allocators (which control memory allocation and deal area for boxes). Function items are important for powerful use of the STL, however the average consumer may be able to forget about allocators maximum of the time with the aid of definitely accepting the default allocator for each box used.
DevOps Interview Questions
Question 21. How Do You Use The Stl?
Answer :
By which include the important header files to allow get entry to to the components of the STL which you need, by using asserting items of the ideal box, iterator and characteristic sorts, and then using member functions and/or algorithms, as suitable, to carry out some thing responsibilities your utility calls for. It is likewise generally important to make certain that anything gadgets you intend to put into your container(s) are objects of training which have a default constructor, a copy constructor, and an overloaded operator=. In addition, in case you plan to type or compare such box gadgets, the corresponding instructions should provide definitions for operator== and operator<. Finally, when you consider that it is regularly the case that distinct containers can be used inside the identical hassle situation, the user wishes so as to make the correct desire for each event, and this desire will commonly be primarily based on overall performance traits.
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 features length(), max_size() and resize().
Understand member capabilities begin(), end(), rbegin() and rend().
Understand the fact that a reference to a "range" of values in STL typically approach the ones values from (and along with) the primary price in the variety up to (but no longer consisting of) the remaining fee inside the range. Such a selection can expand forward or backward, relying at the types of iterators getting used.
Even even though it is able to (on occasion) paintings, it's miles higher not use a loop like for (i = c.Begin(); i < c.Stop(); i++) ... For processing all of the elements of a box c; it's miles most advantageous instead to apply a loop like this: for (i = c.Begin(); i != c.End(); i++) ... This 2d shape is frequently important, in reality, due to the fact that no longer all container iterators assist operator<.
RIt is safest to anticipate 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 characteristic implemented to a container may (or may not) invalidate iterators and references already pointing at elements of that container.
In particular:
It is most secure to assume that insert() implemented to a deque or a vector will invalidate any iterators or references to elements of the deque or vector.
On the other hand, insert() implemented to any of the opposite high-quality bins (list, map, multimap, set, multiset) does now not invalidate any of the iterators or references to factors of the container, and deletions from these boxes invalidate best iterators or references to the factors deleted.
Remember that in case you are the usage of the STL for a given purpose in a state of affairs that requires (as a minimum requirement) that a sure form of iterator be used, a more effective iterator may also be utilized in that state of affairs
Remember that if you have the selection between the usage of an STL set of rules and the use of an STL container magnificence method to accomplish the same purpose, you should prefer the class technique.
Know that any box that is the goal of an set of rules ought to be large enough to preserve all factors it's going to receive, when you consider that it's going to not automatically be multiplied in length. Or, plan to use an inserter.
