C++ Interview Questions
0of 0 votesGiven a circular linked list, find the mid element of the linked list.
0of 0 voteswhat is the difference?
void test(vector<int> vec)
{
//ptint the vec;
}
void test(const vector<int> &vec)
{
//print the vec;
}
0of 0 votesGiven a mathematical expression, remove the redundant brackets from the expression.
e.g. input: (a + (b*c)) * (d * ( f * j) )
output should be: (a + b * c) *d * f * J
operations to support: +, -, /, *, ++, also ternary operators.
0of 0 voteswhich of the following is true for static member of the class?
a) internal linkage
b) external linkage
0of 0 votes#include<iostream>
#include<exception>
int main()
{
try
{
cout << "sum";
throw 3;
}
catch(...)
{
cout<< "dot";
}
catch(int a)
{
cout << a;
}
catch(exception e)
{
cout << "exception";
}
return 0;
}
what will be the output of the above program?
0of 2 votesFor the written test please prepare the following topics throughly :
a) virtual function
b) operator overloading
c) namespace
d) template
For interview, please prepare the container throughly with the implementation of list,map etc.
0of 2 votesclass a{
public:
int var1;
a(int var)
{
var1 = var;
}
};
class b: public a
{
public:
int var2;
b(int d) : var2( d++) , a(var2++)
{
}
};
int main
{
b obj1(5);
}
What will be the value of the variable 'var1' in class A?
a) 6
b)7
c) 5
d) undefined
0of 0 votesclass a{ public: int a; virtual void sum() { printf("sum"); } }; class b : public a { public: int b; virtual void sum() { printf("sum of class b"); } }; void main() { b aptr; a *bptr; bptr = &aptr; bptr->sum(); }Output of the above program?
0of 0 votesWhy the size of the empty class is one?
What are the default functions in an empty class.
does the size of empty class depend upon the compiler or hardware(32 bit or 64 bit)?
0of 0 votes1. What is difference between override and overload
2. abstract. when will u use abstract
3. what is an interface
4. what is difference betwwen array and link list
5. what is a tree
6. what is a map\dictionary
7. Explain (orally) how would you implement a dictionary via a tree
0of 0 votesIf an N X N matrix is given, print it in spiral order.
Example: Below is 5 X 5 matrix
i l o v e
d i n t e
n i e e p
a v w r i
m a x e c
Print in spiral order. Output is iloveepicexamandinterview
-1of 1 votewhere this pointer is stored,how(when) this pointer is initialize ,does it initialize before the construstor call.
-2of 2 votesDesign and code static simulator for all gates .i.e. AND / OR / XOR etc.
Where the simulator has to work properly not only for the binary digit but also for the algebraic inputs (i.e doubles as a input type.)
0of 0 votesHow do we design a class.forName("CLASS") , kind of function?
Where the function will accept a string (as a Class Name) as a parameter and accordingly convert it into the subsequent CLASS object.
0of 0 votesThere are some exceptions that cannot be caught by try catch. How to catch such exceptions? Can we prevent our program to crash if we are not able to catch such exceptions.
0of 0 votesDesign LRU in C++
0of 0 votesDesign Garbage Collector in C++.
0of 0 votesDesign a Tic Tac Toe Game. Classes Segregation and Code Flow.
1of 1 voteWrite a program to sort an array of strings so that all anagrams are next to each other
ex
input {god, dog, abc, cab, man}
output {abc, cab, dog, god, man}
0of 0 votesI have a virtual function in base class BASE and in derived class DERIVED, I have overridden the virtual function. I will create 10 object of DERIVED class.Ex: DERIVED d1,d2...d10. How many v tables are created in this scenario?
0of 0 votesHow is mutual exclusion done in C++?
0of 0 votesHow would you implement Garbage Collection in C++?
0of 0 votesWrite some functions in c/c++ and then re-write the same function that can improve performance(cpu/memory etc) and explain why?
1of 1 voteimplement your own sizeof() operator..
0of 0 votesThe producers write elements to a ring buffer(fixed size) while the consumers access elements from it. Implement a write and a read function using a producer pointer and consumer pointer. The consumer pointer cannot surpass the producer pointer and when the producer pointer reaches where it starts again, it stops.
0of 0 votesGiven a String "abcxrrxabcrr"
Find the first repeated string with minimum 3 character?
Answer is "abc" min 3 characters.
0of 0 votesGiven an input string , "this is apple ****" replace all occurences of "apple" with another word say "freedom" .The interviewer insisted on returning the modified string as an array. No input parameter for writing the output provided.Dont know how can an array be returned in c or cpp . Returning the pointer to a local array would definitely not work .
Please comment.
0of 0 votesA log file which has user details(user ID,timestamp) and pages visited in a particular day by that user.The next day -the same kind of log file gets generated.How do you find the probability of users who logged in consecutive days out of the second day - logged in users? The question is simple,but they look for the efficient data structure and time complexity.
0of 0 votesI am given a third-party library with its header to use. Now this library has a class 'Base'. Problem with this class is that it does not have virtual destructor. Now since i don't have the thirds-party code with me i can not do changes over there.
I am told to write few derived classes with this and make sure that the object gets cleaned properly when objects are delete. How can we achieve this?
0of 0 votesWhy here output is not Derived Class????
#include <iostream>
using namespace std;
class Base {
public:
char* name;
void display() {
cout << name << endl;
}
};
class Derived: public Base {
public:
char* name;
void display() {
cout << name << ", " << Base::name << endl;
}
};
int main() {
Derived d;
d.name = "Derived Class";
d.Base::name = "Base Class";
Derived* dptr = &d;
// standard conversion from Derived* to Base*
Base* bptr = dptr;
// call Base::display()
bptr->display();
}
// OUTPUT
Base Class
