Basic C++ Programming MCQs
Which of the following is the correct way to declare a variable in C++?
- a)
int number;
- b)
int number()
- c)
integer number;
- d)
num int;
Answer: a) int number;
Which function is used to print output to the console in C++?
- a)
print()
- b)
printf()
- c)
echo()
- d)
cout
**Answer: d) cout
What is the correct way to include the standard input-output stream library in a C++ program?
- a)
#include <iostream>
- b)
#include <stdio>
- c)
#include <cstdio>
- d)
#include <conio.h>
Answer: a) #include <iostream>
Which of the following is not a valid C++ identifier?
- a)
int _num;
- b)
int num123;
- c)
int 123num;
- d)
int num_123;
Answer: c) int 123num;
What is the size of the int
data type in C++ (on a typical 32-bit system)?
- a) 1 byte
- b) 2 bytes
- c) 4 bytes
- d) 8 bytes
Answer: c) 4 bytes
Which keyword is used to define a constant variable in C++?
- a)
constant
- b)
final
- c)
const
- d)
define
Answer: c) const
Which of the following is not a loop structure in C++?
- a)
for
- b)
while
- c)
do-while
- d)
repeat-until
Answer: d) repeat-until
Which operator is used to access the value at the address stored in a pointer variable?
- a)
*
- b)
&
- c)
->
- d)
.
Answer: a) *