C++ Programming MCQ (Multiple Choice Questions) : Here Are 1000 Mcqs On C++ (Chapterwise)
C++ Programming MCQ (Multiple Choice Questions) : Here Are 1000 Mcqs On C++ (Chapterwise)
C++ Programming MCQ (Multiple Choice Questions) : Here Are 1000 Mcqs On C++ (Chapterwise)
2. What is C++?
a) C++ is an object oriented programming language
b) C++ is a procedural programming language
c) C++ supports both procedural and object oriented programming language
d) C++ is a functional programming language
View Answer
Answer: c
Explanation: C++ supports both procedural(step by step instruction) and object oriented programming
(using the concept of classes and objects).
3. Which of the following is the correct syntax of including a user defined header files in C++?
a) #include [userdefined]
b) #include “userdefined”
c) #include <userdefined.h>
d) #include <userdefined>
View Answer
Answer: b
Explanation: C++ uses double quotes to include a user-defined header file. The correct syntax of
including user-defined is #include “userdefinedname”.
10. What happens if the following C++ statement is compiled and executed?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
char s1[6] = "Hello";
char s2[6] = "World";
char s3[12] = s1 + " " + s2;
cout<<s3;
return 0;
}
a) Hello
b) World
c) Error
d) Hello World
View Answer
Answer: c
Explanation: There is no operation defined for the addition of character array in C++ hence the
compiler throws an error as it does not understood what to do about this expression.
#include <stdio.h>
int main(void)
{
int new = 5;
printf("%d", new);
}
a) Error in C and successful execution in C++
b) Error in both C and C++
c) Error in C++ and successful execution in C
d) A successful run in both C and C++
View Answer
Answer: c
Explanation: new is a keyword in C++, therefore, we cannot declare a variable with name new but as
there is no such keyword new in C, therefore, the program is compiled and executed successfully in
C.
#include <stdio.h>
void func(void)
{
printf("Hello");
}
void main()
{
func();
func(2);
}
a) Outputs Hello twice in both C and C++
b) Error in C and successful execution in C++
c) Error in C++ and successful execution in C
d) Error in both C and C++
View Answer
Answer: d
Explanation: As the func(void) needs no argument during its call, hence when we are calling func(2)
with 2 as passed as a parameter then this statement gives the error in both C++ and C compiler.
15. Which of the following is correct about this pointer in C++?
a) this pointer is passed as a hidden argument in all static variables of a class
b) this pointer is passed as a hidden argument in all the functions of a class
c) this pointer is passed as a hidden argument in all non-static functions of a class
d) this pointer is passed as a hidden argument in all static functions of a class
View Answer
Answer: c
Explanation: As static functions are a type of global function for a class so all the object shares the
common instance of that static function whereas all the objects have there own instance for non-static
functions and hence they are passed as a hidden argument in all the non-static members but not in
static members.
1. #include <iostream>
2. #include <string>
3. #include <algorithm>
4. using namespace std;
5. int main()
6. {
7. string s = "spaces in text";
8. s.erase(remove(s.begin(), s.end(), ' ' ), s.end() ) ;
9. cout << s << endl;
10. }
a) spacesintext
b) spaces in text
c) spaces
d) spaces in
View Answer
Answer: a
Explanation: In this program, We formed a algorithm to remove spaces in the string.
Output: