CS201 C++ Programming MCQs | 50 Essential Multiple Choice Questions (MCQs) for Virtual University Students

CS201 Introduction to Programming Using C++ | 50 MCQs for VU Students

CS201: Introduction to Programming Using C++

50 Multiple Choice Questions (MCQs) for Virtual University Students

Test Your C++ Programming Skills with These MCQs

  1. Which of the following is the correct way to start a C++ program?
    • a) #include <iostream>
    • b) using namespace std;
    • c) int main()
    • d) System.out.println("Hello World");
  2. What is the output of the following code?
    cout << "Hello, VU!";
    • a) Hello, VU!
    • b) "Hello, VU!"
    • c) cout << "Hello, VU!";
    • d) Error
  3. Which data type is used to store whole numbers in C++?
    • a) float
    • b) int
    • c) double
    • d) char
  4. What symbol is used to end a statement in C++?
    • a) .
    • b) :
    • c) ;
    • d) ,
  5. Which of the following is a valid variable name in C++?
    • a) 2num
    • b) num_1
    • c) int
    • d) #count
  6. What is the size of int data type in most systems?
    • a) 1 byte
    • b) 2 bytes
    • c) 4 bytes
    • d) 8 bytes
  7. How do you declare a constant value in C++?
    • a) const int x = 10;
    • b) int const x;
    • c) Both a and b
    • d) None of the above
  8. What does cin do in C++?
    • a) Prints output
    • b) Takes input from user
    • c) Declares a variable
    • d) Ends the program
  9. Which operator is used for addition in C++?
    • a) +
    • b) -
    • c) *
    • d) /
  10. Which keyword is used to create a loop that executes at least once?
    • a) for
    • b) while
    • c) do-while
    • d) loop
  11. What will be the output of the following code snippet?
    int x = 5; cout << ++x;
    • a) 5
    • b) 6
    • c) 4
    • d) Error
  12. Which of these is the correct syntax to declare an array?
    • a) int arr[] = {1, 2, 3};
    • b) int arr();
    • c) array<int> arr;
    • d) int arr{};
  13. What is the default access specifier for members of a class in C++?
    • a) private
    • b) public
    • c) protected
    • d) friend
  14. What does the return 0; statement signify in the main function?
    • a) Error
    • b) Program executed successfully
    • c) Return value of zero to main
    • d) None
  15. Which header file is required to use cout and cin?
    • a) <stdio.h>
    • b) <iostream>
    • c) <stdlib.h>
    • d) <conio.h>
  16. What is the output of:
    cout << 10 / 4;
    • a) 2.5
    • b) 2
    • c) 3
    • d) 0
  17. What does the following code do?
    for(int i=0; i<5; i++) { cout << i << " "; }
    • a) Prints numbers 0 to 4
    • b) Prints numbers 1 to 5
    • c) Prints numbers 0 to 5
    • d) Infinite loop
  18. What is a pointer in C++?
    • a) Variable that stores address of another variable
    • b) Variable that stores integer value
    • c) Function
    • d) Constant
  19. How do you comment a single line in C++?
    • a) /* comment */
    • b) // comment
    • c) <!-- comment -->
    • d) # comment
  20. Which of the following is the correct way to define a function in C++?
    • a) void func() {}
    • b) int func;
    • c) func void() {}
    • d) function func() {}
  21. What is the output of:
    char ch = 'A'; cout << ch;
    • a) A
    • b) 65
    • c) 'A'
    • d) Error
  22. Which of the following operators is used to access members of a class?
    • a) . (dot)
    • b) ->
    • c) &
    • d) *
  23. Which of the following is true about constructors in C++?
    • a) They have the same name as the class
    • b) They return void
    • c) They must be called explicitly
    • d) They cannot be overloaded
  24. Which loop is best suited for iterating over a known number of times?
    • a) for loop
    • b) while loop
    • c) do-while loop
    • d) if loop
  25. What will be the output of the code?
    int a = 10, b = 20; cout << (a > b ? a : b);
    • a) 10
    • b) 20
    • c) true
    • d) false
  26. Which of these is a valid Boolean value in C++?
    • a) True
    • b) false
    • c) 1
    • d) All of the above
  27. How do you dynamically allocate memory for an integer in C++?
    • a) int *p = new int;
    • b) int p = malloc(sizeof(int));
    • c) int p = new int();
    • d) int *p = malloc(sizeof(int));
  28. Which keyword is used to inherit a class?
    • a) derive
    • b) inherit
    • c) extends
    • d) :
  29. What is the scope resolution operator in C++?
    • a) .
    • b) ::
    • c) ->
    • d) :
  30. What does the following code snippet print?
    int x = 5; cout << x--;
    • a) 6
    • b) 5
    • c) 4
    • d) Error
  31. Which of the following correctly declares a string variable in C++?
    • a) string s = "VU";
    • b) char s = "VU";
    • c) char s[] = "VU";
    • d) Both a and c
  32. What is the purpose of the break statement?
    • a) Terminates the loop or switch statement
    • b) Skips to the next iteration
    • c) Pauses the program
    • d) None
  33. What will be the output of:
    cout << (5 == 5);
    • a) true
    • b) 1
    • c) 0
    • d) false
  34. Which keyword is used to define a class in C++?
    • a) struct
    • b) class
    • c) object
    • d) define
  35. Which operator is used for logical AND in C++?
    • a) &&
    • b) ||
    • c) !
    • d) &
  36. How many times will the loop run?
    for(int i=0; i<3; i++) { cout << i; }
    • a) 2
    • b) 3
    • c) 4
    • d) Infinite
  37. Which of the following is NOT a valid identifier in C++?
    • a) _count
    • b) 1value
    • c) value1
    • d) count_
  38. What is the output of:
    cout << sizeof(char);
    • a) 1
    • b) 2
    • c) 4
    • d) Depends on system
  39. Which of the following is used to define a macro in C++?
    • a) #include
    • b) #define
    • c) #macro
    • d) #macrodef
  40. What is the correct way to start the main function in C++?
    • a) int main()
    • b) void main()
    • c) main()
    • d) main(void)
  41. Which of the following is used to stop a loop from executing?
    • a) continue
    • b) break
    • c) stop
    • d) exit
  42. Which keyword allows a function to be called recursively?
    • a) recursion
    • b) call
    • c) function
    • d) None, all functions can call themselves
  43. Which of the following is a way to allocate memory dynamically?
    • a) malloc()
    • b) new
    • c) Both a and b
    • d) None
  44. Which of these is used for input stream in C++?
    • a) cout
    • b) cin
    • c) scanf
    • d) printf
  45. What is the output of:
    cout << (7 % 3);
    • a) 1
    • b) 2
    • c) 3
    • d) 0
  46. Which operator is used for not equal comparison?
    • a) !=
    • b) ==
    • c) =!
    • d) <>
  47. Which of these is the correct way to declare a pointer?
    • a) int *p;
    • b) int p*;
    • c) pointer p;
    • d) int &p;
  48. Which function is used to deallocate memory allocated by new?
    • a) delete
    • b) free
    • c) remove
    • d) dispose
  49. Which of these is NOT a loop construct in C++?
    • a) for
    • b) while
    • c) do-while
    • d) loop
  50. What does the keyword void signify?
    • a) Function does not return a value
    • b) Variable is empty
    • c) Null pointer
    • d) End of program
  51. Which of the following is correct to print a newline in C++?
    • a) \\n
    • b) /n
    • c) \n
    • d) endl
  52. What does sizeof operator return?
    • a) Size of variable in bytes
    • b) Length of string
    • c) Size of array
    • d) None
  53. Which of the following is NOT a valid access specifier?
    • a) public
    • b) private
    • c) protected
    • d) shared
  54. Which function is the entry point for all C++ programs?
    • a) start()
    • b) main()
    • c) begin()
    • d) init()
  55. Which of the following is used to terminate a function and return control?
    • a) exit
    • b) break
    • c) return
    • d) continue
  56. Which of the following is the correct way to declare a 2D array?
    • a) int arr[2][3];
    • b) int arr[3,2];
    • c) int arr(2,3);
    • d) int arr{2,3};
  57. Which of the following keywords is used for exception handling?
    • a) try
    • b) catch
    • c) throw
    • d) All of the above
  58. Which of the following correctly initializes a vector in C++ STL?
    • a) vector v;
    • b) vector v(5);
    • c) Both a and b
    • d) None
  59. Which operator is used to get the address of a variable?
    • a) *
    • b) &
    • c) #
    • d) %
  60. What is the output of:
    cout << (10 / 3);
    • a) 3
    • b) 3.333
    • c) 4
    • d) 3.0

Post a Comment

0 Comments