1. Which of the following is a correct way to declare a pointer in C/C++?
A. int *ptr;
B. ptr int*;
C. int ptr*;
D. int &ptr;
Answer: A
2. What is the output of the following code snippet? printf("%d", 5 + 10 * 2);
A. 25
B. 20
C. 15
D. 30
Answer: C
3. Which of the following keywords is used to define a constant in C/C++?
A. constant
B. const
C. define
D. static
Answer: B
4. What is the purpose of the #include
directive in C/C++?
A. To define a constant
B. To include header files
C. To declare functions
D. To create loops
Answer: B
5. Which operator is used to access members of a structure in C/C++?
A. ->
B. .
C. *
D. &
Answer: B
6. In C/C++, which of the following is the correct way to allocate memory dynamically?
A. malloc(size);
B. allocate(size);
C. new(size);
D. Both A and C
Answer: D
7. What does the sizeof
operator return?
A. The size of a variable in bytes
B. The size of a variable in bits
C. The number of elements in an array
D. None of the above
Answer: A
8. Which of the following is a valid declaration of an array in C/C++?
A. int arr[];
B. int arr[5];
C. int arr(5);
D. Both A and B
Answer: B
9. What will be the output of the following code snippet? for (int i = 0; i < 5; i++) { printf("%d ", i); }
A. 0 1 2 3 4
B. 1 2 3 4 5
C. 0 1 2 3 4 5
D. 0 2 4
Answer: A
10. Which of the following is not a feature of Object-Oriented Programming?
A. Encapsulation
B. Inheritance
C. Polymorphism
D. Compilation
Answer: D
11. What is the default access specifier for members of a class in C++?
A. Private
B. Protected
C. Public
D. None of the above
Answer: A
12. Which function is used to get the length of a string in C?
A. strlen()
B. strlength()
C. length()
D. size()
Answer: A
13. What is the return type of the main()
function in C/C++?
A. void
B. int
C. char
D. float
Answer: B
14. Which of the following is used to terminate a loop in C/C++?
A. exit
B. break
C. stop
D. return
Answer: B
15. In C/C++, how do you declare a function that returns an integer and takes two integers as parameters?
A. int function(int a, int b);
B. function(int a, int b): int;
C. function(int a, int b) -> int;
D. int function(a, b);
Answer: A
16. What is the purpose of the static
keyword in C/C++?
A. To create a constant variable
B. To declare a variable that retains its value between function calls
C. To define a variable that is only visible within a function
D. Both B and C
Answer: D
17. Which of the following is the correct syntax for a single-line comment in C/C++?
A. // comment
B. /* comment */
C. # comment
D. <!-- comment -->
Answer: A
18. What is the output of the following code snippet? printf("%d", (5 > 3) ? 1 : 0);
A. 0
B. 1
C. 5
D. 3
Answer: B
19. Which of the following operators cannot be overloaded in C++?
A. +
B. *
C. .
D. []
Answer: C
20. In C++, what does the virtual
keyword indicate?
A. The function cannot be overridden
B. The function can be overridden in derived classes
C. The class cannot be inherited
D. The class is an abstract class
Answer: B