Top 100 Basic C++ interview questions and answers list
In this c++ interview questions course, we will be learning:
-
75 c++ interview questions covering basic concepts for freshers
-
top 10 list of c++ interview questions related to competitive programming
-
c++ debugging questions
I have strategically designed these list and assure you this c++ interview questions will help you ace the upcoming interviews. Best of Luck...
Given below is the list of c++ interview questions and answers.Go through it and click on the questions link to read the answer[Link will be updated soon].
C++ interview Questions for freshers
-
What are advantages of C++?
-
Difference between C and C++
-
What is class and object in c++?
-
Types of polymorphism in c++.
-
What is namespace in c++?
-
What are access specifiers in c++?
-
new vs malloc()
-
Explain use of friend function in c++ with examples?
-
What is virtual function in c++?
-
What is constructor in c++ with examples?
-
What is default constructor in c++ with examples?
-
What is destructor in c++ with example?
-
What is operator overloading?
-
What is function overloading?
-
What is virtual inheritance?
-
Explain various OOPS concepts supported by C++?
-
What is use of scope resolution operator in c++ with example?
-
delete vs delete[] in c++
-
What is pure virtual function?
-
Difference struct vs class in c++
-
What is class template in c++?
-
What is virtual destructor in c++?
-
Explain the use of volatile keyword in c++ with examples?
-
What is abstract class in c++?
-
What is reference variable in c++?
-
What is use of static keyword on class member variables?
-
What is static member function?
-
Which access specifier helps in c++ data hiding?
-
Explain delete operator with example.
-
What is copy constructor in c++?
-
Explain the concept of pointer in c++ with example.
-
What is command line argument in c++?
-
What is the use of extern storage specifier?
-
What is header file and their importance in c++?
-
Explain concept of recursion using c++.
-
What is use of keyword ‘using’ in c++
-
Difference == vs = in c++.
-
Explain the static keyword in c++.
-
Floating point operations in c++.
-
What is type casting in c++?
-
What is friend function?
-
Explain function template.
-
Explain class template
-
What is encapsulation?
-
What is compiler and linker?
-
What is the difference between macro and inline?
-
Define memory leak and how to avoid it?
-
Explain pointers.
-
Difference of base and derived class.
-
What is preprocessor directive?
-
Can a program be compiled without main() function?
-
Advantages of using STL in c++.
-
Define local and global scope of an variable.
-
Difference of pre and post increment/decrement with examples.
-
Define void return type in c++.
-
What is inline function in c++?
-
Explain storage classes in c++.
-
DIfference of method overloading and method overriding in c++.
-
Explain pure virtual functions in c++.
-
Does c++ supports exception handling?
-
goto statement in c++.
-
Write code for dynamic allocation in c++.
-
Char to int conversion in c++.
-
Explain enum in c++.
-
Define scope resolution operator in c++.
Comptetive Programming Questions
Problem-solving is a key aspect of any technical interview. Through this interviewer can understand how the person will tackle future real-world problems if the guy gets the job.
I have further furnished list of 12 questions, which are mainly asked in the interviews of various difficulty level basic. These questions are asked mainly in the companies like TCS, CTS, Capgemini, Wipro e.t.c although nowadays as the competition increases they also ask questions on the various topics of DS and Algo like Amazon, Microsoft, Google asked in there interviews.
These questions are equally important for computer science based Government jobs. In ISRO, BARC, NIELIT interviews, they check your depth in any subject which starts with very basics.
Let's start the list.
For solving this question, first, you need to understand Fibonacci series and if you are solving this question with recursion, then the concept of recursion otherwise loops concept.
Concept of palindrome required as well as string concept and loops
3. Conversions
Binary to decimal, binary to octal, decimal to octal.
And the vice-versa of the above ones. You need to have knowledge of all this as well as some extent concept of arrays.
4. Pattern Printing
Mostly pyramid and diamond patterns are asked. For this, you need the knowledge of loops as well as matrices.
5. GCD of two numbers
GCD concept is required as well as loops concept. The tricky part of this question is they can ask you to solve this question on O(nlogn) Time complexity. Then you need to use the concept of Euclidean algorithm
6. Prime Number
Concept of the prime number required here, like the above question if the time complexity is the matter then we need to use Sieve of Eratosthenes algorithm
7. Call by Reference
For solving any problem related to this, you need the concept of pointers.
8. Student Database
For making a student database, you need the concept of structure and unions.
9. Basic problem-solving questions on Array
Questions like remove a duplicate, second largest element in the array this type of questions can be asked. For solving this type of question Time Complexity is an important matter.
10. Problems on Mathematics:
Questions like sum of square numbers, e^x value, permutation and combinations. For solving this type of question basic mathematics skill and array with pointer concept required.
11. Problems on Matrices:
Questions can come on matrix multiplication, rotation and c++ code need to be written in an optimized way.
12. STL related:
Standard Template Library is an important addition to C++. So interviewer can ask you to write a basic code snippet using STL or vector-related questions can be there.
C++ Debugging questions
1. Find the output of below program
void main()
{
int x;
for(x=1;x<=4;x++)
{
switch(x)
{
case 1: cout<
break;
case 2: cout<
break;
case 3: cout<
break;
case 4: cout<
break;
}
}
}
2. Output of below program is:
int main()
{
int j;
unsigned char i=0x80;
j=i<<1;
cout<<j;
return 0;
}
3.
int main()
{
int i=10;
i=!i>14;
cout<<i;
return 0;
}
Output of above program will be?
4. Output of the program is?
int main()
{
int x=20,y=35;
x=y+++x++;
cout<<x<<" "<<y;
return 0;
}
5. Return value of fun(5) is?
int fun(int n)
{
int x=1,k;
if(n==1) return x;
for(k=1;k<n;++k)
x=x+fun(k)*fun(n-k);
return x;
}
6. Output of below c++ code?
#include<iostream>
using namespace std;
void nic(int *p)
{
int i=0;
for(i=0;i<5;i++)
cout<<p[i];
}
int main()
{
int a[5]={6,5,3};
nic(&a);
return 0;
}
7.
int fun(int n)
{
if (n/10==0)
return (n%10);
else
return fun(n%10+fun(n/10));
}
Return value of fun(9874) in above pseudo code?
8. Output of below program is?
a) 65472 65480 b) 65472 65490
c) 65472 65496 d) 65480 65496
int main()
{
/* Assume array begins at the address 65472 and size of int is 2 */
int k;
int a[3][4]
=
{ 1, 2, 3, 4
5, 6, 7 ,8
9, 10, 11, 12
}
k=&a+1;
cout<<a+1<<" "<<k;
return 0;
}
9. Output of below c++ code?
#include<iostream>
using namespace std;
void tih(int *x,int *y)
{
int t=*x;
*x=*y;
*y=temp;
}
int main()
{
int i=7,j=10;
cin>>i>>j;
tih(&i,&j)
cout<<i<<" "<<j;
}
10. Identify error in below program.
#include<iostrem.h>
class Room
{
int w,h;
void Val(int w1,int h1)
{
w=w1;
h=h1;
}
};
void main()
{
Room obRoom;
obRoom.w=12;
}
11. Identify error in below program:
#include<iostream.h>
class TIH
{
int a,b;
public:
TIH(int a1, int w=0):
b(w),a(l)
{
}
};
void main()
{
TIH objT;
TIH objT(12,8);
}
12. Output of below pseudo code is?
arr[]={1,2,3,4,5}
initialize i,n
intialize and array of size n
accept the values for the array
for o to n
arr[i] = arr[i]+arr[i+1]
end for
print the array elements
13.
Integer a
String str1
Set str1 = “goose”
a = stringLength(str1)
Print (a ^ 1)
Output of above pseudo code is?
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Page Views :
Published Date :
Jan 27,2021