C++ MCQ Questions with Answers – Part 7
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. Evaluate the following expression :
(false && true) || false || true
A Compilation error
B 0
C False
D 1
2. Which of the following codes will display an error during compilation?
Code 1 :
#include <iostream> using namespace std; int main(int argc, char const *argv[]) { cout << "Welcom to StackHowTo"; return 0; }
Code 2 :
#include <iostream> int main(int argc, char const *argv[]) { std::cout << "Welcom to StackHowTo"; return 0; }
A Code 1 and Code 2
B Only code 1
C Only code 2
D Neither code 1 nor code 2
3. Which of the following gives the memory address of the first element of the array?
A arr[0];
B arr[1];
C arr(2);
D arr;
4. What is the result of the following C++ program?
#include <stdio.h> #include<iostream> using namespace std; int main () { int arr[] = {0, 2, 4, 2, 1}; int n, s = 0; for (n = 0; n < 6; n++) { s += arr[n]; } cout << s; return 0; }
A 8
B 10
C 9
D None of the above
5. What will happen in this code?
int x = 10, y = 20; int *p = &x, *q = &y; p = q;
A y is assigned to x
B p now points to y
C x is assigned to y
D q now points to x
6. What is the output of the following code?
#include <iostream> using namespace std; int main() { char c = 65; cout << c; return 0; }
A N
B I
C J
D A
7. What is the output of the following code?
#include <iostream> using namespace std; int main() { char *p; char str[] = "StackHowTo"; p = str; p += 5; cout << p; return 0; }
A StackHowTo
B Stack
C HowTo
D H
8. Which of the following will not return a value?
A null
B void
C empty
D free
9. What does the following statement mean?
void a;
A Variable a is of type void
B a is an object of type void
C Declares a variable with the value a
D Report an error
10. Select the wrong option?
A void is used when the function does not return a value
B void is also used when the value of a pointer is null
C void is used as a base type for pointers to objects of unknown type
D void is a special type