
C/C++ Interview Questions and Answers
Top 100 C/C++ Programming Interview Questions for Freshers
C and C++ are among the most powerful and widely used programming languages in software development. Mastering these languages allows developers to build high-performance applications, system software, game engines, and embedded systems. Candidates should also be prepared to tackle both the C/C++ Online Assessment and Technical Interview Round at IDM TechPark.
To help you succeed, we have compiled a list of the Top 100 C/C++ Interview Questions along with their answers. Mastering these will give you a strong edge in cracking C/C++ interviews and excelling in software development roles.
1. What is C?
C is a procedural programming language used for system programming and application development.
2. What is C++?
C++ is an extension of C that supports both procedural and object-oriented programming.
3. What are the key features of C?
-
Simple and efficient
-
Fast execution
-
Low-level memory manipulation
-
Rich library support
4. What are the key features of C++?
-
Object-oriented programming (OOP)
-
Encapsulation, Inheritance, Polymorphism
-
Faster execution and efficiency
5. What is the difference between int, float, and char?
-
int: Stores integers (e.g., 10, -5)
-
float: Stores decimal values (e.g., 3.14, -2.5)
-
char: Stores a single character (e.g., 'A', 'b')
6. What are the different types of loops in C/C++?
-
for loop
-
while loop
-
do-while loop
cpp
CopyEdit
for (int i = 0; i < 5; i++) { cout << i; }
7. What is a pointer in C?
A pointer is a variable that stores the address of another variable.
cpp
CopyEdit
int x = 10; int *ptr = &x; // Pointer to x
8. What is the difference between = and == in C/C++?
-
= is an assignment operator (x = 5;)
-
== is a comparison operator (if (x == 5))
9. What is an array in C?
A collection of elements of the same data type stored in contiguous memory locations.
cpp
CopyEdit
int arr[3] = {1, 2, 3};
10. What is a function in C/C++?
A reusable block of code that performs a specific task.
cpp
CopyEdit
int add(int a, int b) { return a + b; }
11. What is the main() function?
The entry point of a C/C++ program where execution starts.
cpp
CopyEdit
int main() { return 0; }
12. What is printf() and scanf()?
-
printf() is used for output.
-
scanf() is used for input.
c
CopyEdit
int x; scanf("%d", &x); printf("Value: %d", x);
13. What is cin and cout in C++?
C++ uses cin for input and cout for output.
cpp
CopyEdit
int x; cin >> x; cout << "Value: " << x;
14. What is the difference between break and continue?
-
break exits a loop completely.
-
continue skips the current iteration.
cpp
CopyEdit
for (int i = 1; i <= 5; i++) { if (i == 3) continue; cout << i; }
15. What is a switch statement?
A multi-way branch statement that replaces multiple if-else conditions.
cpp
CopyEdit
switch (x) { case 1: cout << "One"; break; case 2: cout << "Two"; break; default: cout << "Other"; }
16. What is the difference between while and do-while loops?
-
while checks the condition before executing the loop.
-
do-while executes the loop at least once before checking the condition.
cpp
CopyEdit
do { cout << "Hello"; } while (false);
17. What is sizeof operator?
Returns the size of a variable or data type in bytes.
cpp
CopyEdit
cout << sizeof(int);
18. What is recursion in C/C++?
A function that calls itself.
cpp
CopyEdit
int factorial(int n) { if (n == 1) return 1; return n * factorial(n - 1); }
19. What is a structure in C?
A user-defined data type that groups different types of data together.
cpp
CopyEdit
struct Student { int id; char name[20]; };
20. What is a class in C++?
A class is a blueprint for creating objects in C++.
cpp
CopyEdit
class Car { public: string brand; void show() { cout << brand; } };
21. What is the difference between struct and class in C++?
-
In struct, members are public by default.
-
In class, members are private by default.
22. What is an object in C++?
An object is an instance of a class.
cpp
CopyEdit
Car c1; c1.brand = "Toyota"; c1.show();
23. What is inheritance in C++?
A mechanism that allows a class to derive properties from another class.
cpp
CopyEdit
class A {}; class B : public A {}; // B inherits from A
24. What is a constructor in C++?
A special function that initializes objects.
cpp
CopyEdit
class Car { public: Car() { cout << "Constructor called"; } };
25. What is a destructor in C++?
A function that is called when an object is destroyed.
cpp
CopyEdit
class Car { public: ~Car() { cout << "Destructor called"; } };