Important C++ Interview Questions For Freshers
Important C++ Interview Questions For Freshers
Asked C ++
Interview
Questions
w i t h a n s w e r s
Join WhatsApp Group for
Basic Level
Placement
Talent Battle has partnered with TCS iON offering 4000+ internships to students all
over the country. Talent Battle provides aptitude, coding, interview preparation,
latest technologies related training.
www.talentbattle.in
2. What are classes and objects in C++? Get free mentorship
from experts?
Answer:
A class is like a blueprint of an object. It is a user-defined data type with data
members and member functions and is defined with the keyword class.
You define objects as an instance of a class. Once it creates the object, then it
can operate on both data members and member functions.
Answer:
The equal to operator == checks whether two values are equal or not. If equal,
then it’s true; otherwise, it will return false. The assignment operator = allots the
value of the right-side expression to the left operand.
5. What is the difference between a while loop
Follow us on Instagram
and a do-while loop?
Answer:
Options:
a. -
b. +
c. ?:
d. %
Answer:
c - ?: operator cannot be overloaded because it is not syntactically possible.
Options:
a. Size
b. Length
c. Both size and length
d. Name
Answer:
Both size and length are used to return the number of characters in the string.
Answer:
In prefix (++i), first, it increments the value, and then it assigns the value to
the expression.
In postfix (i++), it assigns the value to the expression, and then it
increments the variable's value
10. Can you compile a program without Join WhatsApp Group for
the main function? Placement
Answer:
Yes, you can compile a program without the main function, but you
cannot run or execute the program because the main() function is
the entry point, from where all the execution begins.
Answer:
std is a standard namespace in C++
Answer:
Primitive/Basic: Char, int, short, float, double, long, bool, etc.
Enumeration: Enum
Answer:
Answer:
The term polymorphism refers to the presence of multiple forms.
Polymorphism usually occurs when there is a hierarchy of classes that are
linked by inheritance.
C++ polymorphism means that depending on the type of object that
invokes the function, a different function will be executed.
Answer:
In C++, a function Object is a particular "MEMBER FUNCTION" that shares
the same
title as the class it belongs to and is used to initialize specific values to an
object's data members.
#include <iostream>
using namespace std;
class student {
int no;
public:
student()
{
cout << "Enter the RollNo:";
cin >> rno;
}
{
Follow us on
cout << endl << rno << "\t"; YouTube!
}
};
int main()
{
student s; // constructor gets called automatically when
// we create the object of the class
s.display();
return 0;
}
19. What are the three different types of C++ access specifiers?
Answer:
Public: All member functions and data members are accessible outside
the class.
Protected: All member functions and data members are accessible within
the class and to the derived class.
Private: All member functions and data members cannot be accessed
outside the class.
20. What is an abstraction in C++? Join WhatsApp Group for
Placement
Answer:
Abstraction means displaying the essential details to the user
while hiding the irrelevant or particular details that you don’t
want to show to a user. It is of two types:
Control abstraction
Data abstraction
Answer:
No, it is impossible as destructors do not take arguments or return anything.
There has to be only one empty destructor per class. It should have a void
parameter list.
25. What is the C++ OOPs concept? Join WhatsApp Group for
Placement
Answer:
Object
Class
Inheritance
Polymorphism
Encapsulation
Abstraction
Object: Anything that exists physically in the real world is called an object.
Answer:
In the call by value method, you pass the copies of actual parameters to the
function's formal parameters. This means if there is any change in the values
inside the function, then that change will not affect the actual values.
Syntax:
Inline return-type function-name(parameters)
{
}
Place
d in A Rohit Borse
ccent
ure
Shrinija
Kalluri 6.5 LP
Placed in
Oracle A
9 LPA
29. What are pointers in C++? Follow us on Instagram
Answer:
Pointers are the variables that store the memory address of
another variable. The type of the variable must correspond with
the type of pointer.
Answer:
012, the value of i is 0 and i % 5 is equal to 0, so x is displayed and incremented
and i is also incremented, then 1 % 5 is not zero, so the condition is not met.
Similarly, the process will repeat till 4 % 5 because 5 % 5 is zero. So the value of x
is one and gets incremented to two. Then, the process will repeat for 6,7,8,9, but
10 % 10 will be zero again, and the value of x is printed, which is 2.
class A
{
};
int main()
{
A a1,a2,a3;
a3= a1 + a2;
return 0;
}
34. How to input strings in C++ with spaces? Join WhatsApp Group for
Placement
Answer:
Answer:
Answer:
0 6.
In enum, the element's value is one greater than the previous element. The value
of blue is 0 by default, and the value of green is five, so the value of GREAT will
become six automatically.
Talent Battle is
associated with TCS iON
for content partnership &
providing internships to
students across India.
38. Which among the following statements is correct about the
program given below?
Options:
a. The output will be 7
b. The output will be 14
c. The output will be 0
d. The output will be 1
Answer:
Output will be 7. Pointer p has the memory address of x, and you display the
pointer with a dereference operator that will display the value 7.
39. Which among the following statements is correct about the
program given below?
Follow us on
YouTube!
Options:
a. The output will be 245
b. The output will be 222
c. The output will be 4810
d. The output will be 4812
Answer:
Output will be 4810, because you are passing the references of the
function here.
Answer:
You can define a friend function as a function that can access private,
public and protect members of the class. You declare the friend
function with the help of the friend keyword. You declare this function
inside the class.
41. Which of the following will give the size of object or type?
Options:
a. sizeof
Get free mentorship
b. malloc from experts?
c. realloc
d. calloc
Answer:
The sizeof operator is used to give the size of object or type
Answer:
friend function is not a member of the class
Answer:
A copy function is a member function that uses another object from the same
class to initialize a new thing. A copy function is, to put it simply, a function that
produces an object by initializing it with a different object of the same class that
has already been constructed.
#include <iostream>
using namespace std;
class A
{
Public:
int x;
A(int a) // parameterized constructor.
{
x=a;
}
A(A &i) // copy constructor
{
x = i.x;
}
};
int main()
{
A a1(20); // Calling the parameterized constructor.
A a2(a1); // Calling the copy constructor.
cout<<a2.x;
return 0;
}
Answer:
Abstraction can be defined as a technique in which you only show
functionality to the user i.e., the details that you want the user to see,
hiding the internal details or implementation details.
Options:
a. 5
b. 4
c. 7
d. 6
Answer:
6, Ternary operator is used, the value of a is less than b which violates
the condition that is why 6 is the answer.
50. How to find the frequency of a number in C++?
Answer:
Follow us on
YouTube!
Answer:
1010, the value of j is incremented to 11, then j value is added to 100 but not
assigned, and at last the value of j i.e 11 is added to 999 which gives us 1010.
Answer:
String objects have a dynamic size.
Answer:
The derived class consists of two parts: the base part and the derived
part. C++ constructs derived objects in phases. The process begins with
constructing the most-base class (at the top of the inheritance tree),
followed by each child class construction in order, and then the most-
child class. Thus, first, the Constructor of class B will be called, and then
the constructor of class D.
class Dog{
void make(){
System.out.println("labrador");
}
}
public class Big extends Dog{
void make(){
System.out.println("Big Dog labrador ");
}
public static void main(String args[]){
Dog ob1 = new Big();
ob1.make();
}
}
57. What are void pointers? Get free mentorship
from experts?
Answer:
In C, a void pointer has no connection to any particular data type. It
designates a location for specific data within the storage. This indicates
that it is pointing to a variable's address. It also goes by the name
"general purpose pointer."
#include <iostream>
using namespace std;
int main()
{
int a = 10;
char b = 'x';
void* p = &a; // void pointer holds address of int 'a'
p = &b; // void pointer holds address of char 'b'
}
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
char *user;
user = (char *) malloc(25);
strcpy(user, "Jane_Eyre");
cout << "User Name = " << user << " " << &user << endl;
free(user);
Industry Mentors
@talentbattle.in
@talentbattle_2023
@talentbattle_2024
@talentbattle_2025
@talentbattle_2026
WhatsApp Group
Free Mentorship
Talent Battle Facebook
Talent Battle YouTube
Talent Battle LinkedIn
https://talentbattle.in/