Standard Template Library (STL) Interview Questions And Answers
Download Standard Template Library (STL) Interview Questions and Answers PDF
Elevate your Standard Template Library (STL) interview readiness with our detailed compilation of 16 questions. Each question is designed to test and expand your Standard Template Library (STL) expertise. Suitable for all experience levels, these questions will help you prepare thoroughly. Download the free PDF to have all 16 questions at your fingertips. This resource is designed to boost your confidence and ensure you're interview-ready.
16 Standard Template Library (STL) Questions and Answers:
Standard Template Library (STL) Job Interview Questions Table of Contents:
1 :: Write a program in C++ returning starting locations of a substring using pointers?
#include<stdio.h>
#include<iostream.h>
int main()
{
char* mystrstr(char*,char*);
char str1[20];
char str2[10];
cout<<"\n Enter two strings\t";
cin>>str1>>str2;
cout<<"\nstr1 = "<<str1<<" str2 "<<str2 ;
char* c= mystrstr(str1,str2);
if(c!=NULL)
printf("\nc = %s\n",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 found\n");
return(cp);
}
cp++;
}
return(NULL);
}
Read More#include<iostream.h>
int main()
{
char* mystrstr(char*,char*);
char str1[20];
char str2[10];
cout<<"\n Enter two strings\t";
cin>>str1>>str2;
cout<<"\nstr1 = "<<str1<<" str2 "<<str2 ;
char* c= mystrstr(str1,str2);
if(c!=NULL)
printf("\nc = %s\n",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 found\n");
return(cp);
}
cp++;
}
return(NULL);
}
2 :: Write a program in C/C++ to implement reader- writer problem?
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 startRead()/startWrite()
to enter the
Database and it must call endRead()/endWrite() to exit the
Database.
class Database extends Object {
private int numReaders = 0;
private int numWriters = 0;
private ConditionVariable OKtoRead = new ConditionVariable
();
private ConditionVariable OKtoWrite = new ConditionVariable
();
public synchronized void startRead() {
while (numWriters > 0)
wait(OKtoRead);
numReaders++;
}
public synchronized void endRead() {
numReaders--;
notify(OKtoWrite);
}
public synchronized void startWrite() {
while (numReaders > 0 || numWriters > 0)
wait(OKtoWrite);
numWriters++;
}
public synchronized void endWrite() {
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(ConditionVariable cond) {
put the calling thread on the “wait set” of cond;
release lock;
Thread.currentThread.suspend();
acquire lock;
}
notify(ConditionVariable cond){
choose t from wait set of cond;
t.resume();
}
notifyAll(ConditionVariable cond){
forall 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.
Read MoreThe 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 startRead()/startWrite()
to enter the
Database and it must call endRead()/endWrite() to exit the
Database.
class Database extends Object {
private int numReaders = 0;
private int numWriters = 0;
private ConditionVariable OKtoRead = new ConditionVariable
();
private ConditionVariable OKtoWrite = new ConditionVariable
();
public synchronized void startRead() {
while (numWriters > 0)
wait(OKtoRead);
numReaders++;
}
public synchronized void endRead() {
numReaders--;
notify(OKtoWrite);
}
public synchronized void startWrite() {
while (numReaders > 0 || numWriters > 0)
wait(OKtoWrite);
numWriters++;
}
public synchronized void endWrite() {
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(ConditionVariable cond) {
put the calling thread on the “wait set” of cond;
release lock;
Thread.currentThread.suspend();
acquire lock;
}
notify(ConditionVariable cond){
choose t from wait set of cond;
t.resume();
}
notifyAll(ConditionVariable cond){
forall 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.
4 :: Explain method overloading?
Method overloading is to overload methods using same class
name by writing different parameters.This is called Method
Overloading.
Read Morename by writing different parameters.This is called Method
Overloading.
5 :: What is sorted linked list?
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 hold the referance of the next
node.
if we talk about the sorted linked list , it is also a list
just like another list. but the differce is only that it
hold all the nodes in a sequantial manner either in
accending order decending order
Read Morea line. it means that each node is connected with another
one. Each node of the list hold the referance of the next
node.
if we talk about the sorted linked list , it is also a list
just like another list. but the differce is only that it
hold all the nodes in a sequantial manner either in
accending order decending order
6 :: What is the acronym of the term C.O.M.P.U.T.E.R?
common operater meachine a particular user technical
education research
OR
C - Conventional
O - Organization of
M - Man
P - Power
U - Utilitilised
T - Tachnical
E - Enhancement
R - Resource.
Read Moreeducation research
OR
C - Conventional
O - Organization of
M - Man
P - Power
U - Utilitilised
T - Tachnical
E - Enhancement
R - Resource.
7 :: Tell me about c++?
c++ is object oriented programming language.. the main
function value should return.
Read Morefunction value should return.
8 :: How to get the sum of two integers?
#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);
}
Read More#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);
}
9 :: Why we are using the fork command and how it works?
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
Read Moreprocess. The Child process inherits some properties of its
parent and operates in a separate memory space
10 :: Write a c++ program to create an object of a class called employee containing the employee code name designation basic salarry HRA Da gross salary as data 10 such objects "members process "?
#include<iostream.h>
#include<conio.h>
class person
{
int person;
float salery;
}p;
cout<<"enter the person name";
cin>>p.person;
cout<<"enter the salery";
cin>>p.salery;
}
void main()
{
person;
getch();
}
Read More#include<conio.h>
class person
{
int person;
float salery;
}p;
cout<<"enter the person name";
cin>>p.person;
cout<<"enter the salery";
cin>>p.salery;
}
void main()
{
person;
getch();
}
11 :: #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?
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
Read Morethe 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
12 :: Why & sign is used in copy constructor?
To avoid local copy of object reference (&) is used in copy
constructor.
Moreover if the & is ommited 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.
Read Moreconstructor.
Moreover if the & is ommited 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.
14 :: Write a c++ to define a class box with length, breadth and height as data member and input value(), printvalue() and volume() as member functions?
#include<iostream.h>
#include<conio.h>
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()
{
cout<<"volume="<<"\n";
}
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;
}
Read More#include<conio.h>
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()
{
cout<<"volume="<<"\n";
}
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;
}
15 :: Tell me What is the difference between thread and process?
Thread is a smallest unit of process. In process have one
or more thread.
Read Moreor more thread.
16 :: WHAT IS THE DIFFERENCE BETWEEN C++ AND VC++?
VC++ uses all C++ features. VC++ has GUI and it is user
friendly.It has many programming features
likeWin32, MFC, ATL, ActiveX, DLL's etc.
Read Morefriendly.It has many programming features
likeWin32, MFC, ATL, ActiveX, DLL's etc.