C++ MCQ Questions and Answers – Part 3
Multiple choice questions and answers (MCQs) on C++ to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as Variables, Operators, Conditional Statement, Functions, and more. This quiz will easily prepare anyone to pass their online test.
1. What happens if the following program is run in C and C++?
#include<stdio.h> int main() { display(); } int display() { printf("Hello World!"); return 0; }
A Error in C and C++
B Warning in C and C++
C Error in C++ but warning in C
D Error in C but warning in C++
2. Which of the following types is not present in C but present in C++?
A void
B bool
C float
D int
[st_adsense]
3. What is the size of a boolean variable in C++?
A 1 bit
B 1 byte
C 4 bytes
D 2 bytes
4. What is the output of the following code in C++?
#include <iostream> using namespace std; int main() { int a = 4; float b; cout << sizeof(++a + b) << endl; cout << a; return 0; }
A 5 4
B 4 5
C 4 4
D 2 4
5. Which of the following statements is equivalent to scanf() in C++?
A cin
B cout
C printf
D read
[st_adsense]
6. Which of the following statements is equivalent to printf() in C++?
A cin
B cout
C scanf
D write
7. What happens if the following program is run in C and C++?
#include <stdio.h> int main(void) { const int a = 10; int *ptr = &a; printf("*ptr = %d", *ptr); return 0; }
A Error in C and C++
B Warning in C and C++
C Error in C++ but warning in C
D Error in C but warning in C++
8. What is the difference between cin and scanf()?
A Both are the same.
B cin is a flow object while scanf() is a function.
C scanf() is a flow object while cin is a function.
D cin is used for displaying while scanf() is used to read inputs.
[st_adsense]
9. What happens if the following program is run in C and C++?
#include<stdio.h> int main() { char x = 'x'; printf("%d\n", (int)sizeof(x)); return 0; }
A The output in C is 4 and in C++ is 4
B The output in C is 1 and in C++ is 1
C The output in C is 4 and in C++ is 1
D The output in C is 1 and in C++ is 4
10. What is the output of the following C++ code?
#include <iostream> using namespace std; int main() { char arr[4] = "abcd"; cout << arr; return 0; }
A abcd
B Warning
C Error: the string in the array is too long.
D None of the above
[st_adsense]