C++ QUESIONS
1. Define C++?
C++ is a general-purpose, object-oriented programming language that supports both high-
level and low-level features.
2. Why we use C++?
C++ is used for developing system software, games, and large-scale applications due to its
performance and object-oriented features.
3. Difference between C & C++?
C is a procedural programming language, while C++ supports both procedural and object-
oriented programming.
4. What are Header Files?
Header files in C++ contain declarations of functions, classes, and variables used in a program
(e.g., #include <iostream>).
5. What is Preprocessor Directive?
Preprocessor directives are commands that begin with # and are processed before the actual
compilation (e.g., #include, #define).
6. What is Main Function?
The main() function is the entry point of every C++ program where execution begins.
7. Define Loops?
Loops are control structures that execute a block of code repeatedly while a condition is true
(e.g., for, while, do-while).
8. Define Functions?
Functions are blocks of code designed to perform specific tasks.
9. Define Arrays?
An array is a collection of elements of the same type stored in contiguous memory locations.
10. Define File Handling?
File handling in C++ refers to reading from and writing to files using streams like ifstream,
ofstream, and fstream.
11. Define Pointers?
Pointers are variables that store memory addresses of other variables.
12. Enlist Data types in C++?
int, float, double, char, bool, void.
13. Enlist Operators in C++?
Arithmetic, Comparison, Logical, Bitwise, Assignment,
14. What is Assignment Operator?
An assignment operator (=) assigns the value on the right to the variable on the left.
15. Define Variable Declaration?
Declaring a variable means telling the compiler its name and data type (e.g., int x;).
16. Define Variable Initialization?
Initializing a variable means assigning an initial value at the time of declaration (e.g., int x = 5;).
17. Define Variables?
Variables are named memory locations used to store data during program execution.
18. Define between Local & Global variables?
Local variables are declared inside a function and accessible only there.
Global variables are declared outside all functions and accessible throughout the program.
19. What is Concatenation?
Concatenation means joining two strings together using the + operator or append() function.
20. What is Errors?
Errors are problems in the code that prevent it from compiling or running correctly.
21. What is Syntax Error?
A syntax error occurs when the rules of the language are not followed (e.g., missing ;).
22. What is Run Time Error?
Runtime errors occur while the program is running, such as division by zero or invalid memory
access.
23. What is Break Statement?
break is used to exit a loop or switch statement before it naturally ends.
24. Write a syntax for Nested If Statement?
if (condition1) {
if (condition2) {
// code
}
}
25. What is the method of function calling?
Functions are called using their name followed by parentheses, e.g., myFunction();.
26. What is the usage of go-to statement?
goto is used to jump to a labeled part of the code, though its use is discouraged due to poor
readability.
27. Difference between && and || operators in statements of C++?
&& (AND): true if both conditions are true.
|| (OR): true if at least one condition is true.
28. What is the usage of increment and decrement?
++ increases a variable’s value by 1, and -- decreases it by 1.
29. Difference between while & do-while loop?
while checks condition before executing.
do-while executes first, then checks condition.
30. What is return statement?
return ends a function and optionally sends a value back to the caller.
31. What is the usage of * and & operator in pointers?
* (dereference) accesses the value at a pointer.
& (address-of) gets the memory address of a variable.
32. What is functions?
Functions are reusable blocks of code that perform specific tasks and can return values.