C and C++ interview questions

Basic C Questions
-
What is C language?
-
What are the features of C?
-
What is a compiler?
-
What is the difference between compiler and interpreter?
-
What is a variable in C?
-
What is a data type? Give some examples.
-
What are keywords in C?
-
What is the difference between
int
,float
, andchar
? -
How do you write a simple "Hello World" program in C?
-
What is the use of
main()
function?
C Operators & Control Statements
-
What are arithmetic operators in C?
-
What is the difference between
=
and==
? -
What are logical operators?
-
What is the use of if-else?
-
What is the difference between
while
anddo-while
loop? -
What is a switch statement?
-
What is a break statement?
-
What is a continue statement?
-
What is a ternary operator?
-
What is the use of
goto
in C?
Functions in C
-
What is a function?
-
What is the difference between call by value and call by reference?
-
Can we return multiple values from a function?
-
What is recursion?
-
What is the scope of a variable?
-
What is a static variable?
-
What is an inline function?
-
What is the difference between
void
andint
return type? -
What is the use of
return
statement? -
What is function overloading? Is it supported in C?
Arrays, Strings, and Pointers in C
-
What is an array?
-
How to declare and use a 2D array?
-
What is a string in C?
-
How are strings stored in memory?
-
What is a pointer?
-
How to declare a pointer?
-
What is the use of
*
and&
in pointers? -
What is a NULL pointer?
-
What is a dangling pointer?
-
How can you use pointers with arrays?
Structures and Unions
-
What is a structure in C?
-
How is a structure different from an array?
-
What is a union?
-
What is the difference between structure and union?
-
Can we use pointers with structures?
-
Can we pass a structure to a function?
-
What is
typedef
? -
Can we nest structures?
-
What is padding in structure?
-
What is the size of an empty structure?
Memory Management
-
What is dynamic memory allocation?
-
What is the use of
malloc()
? -
What is the use of
calloc()
? -
What is
realloc()
? -
What is
free()
? -
What are memory leaks?
-
How can you avoid memory leaks?
-
What is stack vs heap memory?
-
What happens if you free a NULL pointer?
-
What is the difference between static and dynamic memory?
File Handling in C
-
How to open a file in C?
-
What is the use of
fopen()
? -
How to read and write in a file?
-
What is
fprintf()
andfscanf()
? -
What is the difference between
fgets()
andgets()
? -
How to close a file?
-
What is the difference between text and binary files?
-
What is
fseek()
used for? -
How to append data to a file?
-
What are file modes in
fopen()
?
Basic C++ Questions
-
What is C++?
-
What are the main features of C++?
-
What is object-oriented programming (OOP)?
-
What is a class in C++?
-
What is an object?
-
What is encapsulation?
-
What is inheritance?
-
What is polymorphism?
-
What is abstraction?
-
What is constructor and destructor?
Advanced C++ Concepts
-
What is function overloading in C++?
-
What is operator overloading?
-
What is the difference between method overloading and overriding?
-
What is a virtual function?
-
What is a pure virtual function?
-
What is an abstract class?
-
What is the use of
this
pointer? -
What is the difference between
new
andmalloc()
? -
What is multiple inheritance?
-
What is a friend function?
General & Miscellaneous
-
What is the difference between C and C++?
-
What is a header file?
-
What is the difference between
#include <file>
and#include "file"
? -
What is a segmentation fault?
-
What is the difference between compile time and runtime?
-
What is a linker and loader?
-
What is the use of preprocessor directives like
#define
? -
What is macro?
-
What is the use of
const
? -
What are best practices in C/C++ programming?