
computer programming mcqs with answers pdf
What does the static keyword indicate when used with a class member variable in C++?
- A) It specifies that the variable is shared among all instances of the class.
- B) It declares the variable as constant.
- C) It denotes that the variable is accessible only within its containing function.
- D) It signifies that the variable is dynamically allocated.
Correct Answer: A) It specifies that the variable is shared among all instances of the class.
Which data structure in C++ follows the Last In, First Out (LIFO) principle?
- A) Queue computer programming mcqs with answers pdf
- B) Array
- C) Stack
- D) Linked List
Correct Answer: C) Stack
What is the purpose of the virtual keyword when used with a function in a base class in C++?
- A) It indicates that the function cannot be overridden in derived classes.
- B) It enables dynamic binding and late binding.
- C) It specifies that the function is pure virtual and must be overridden in derived classes.
- D) It makes the function inline for performance optimization.
Correct Answer: B) It enables dynamic binding and late binding.
________ operator function is to access the value stored at a memory address in C Plus Plus?
- A) & computer programming mcqs with answers pdf
- B) *
- C) ->
- D) ::
What does the new operator return if memory allocation fails in C++?
- A) nullptr
- B) -1
- C) 0 computer programming mcqs with answers pdf
- D) It throws an exception
Which of the following correctly declares a pointer to a function in C++?
- A) int (*ptr)();
- B) int *ptr();
- C) int *ptr;
- D) int ptr();
Correct Answer: A) int (*ptr)();
In C++, which header file should be included to use the exit() function?
- A) <stdio.h>
- B) <stdlib.h>
- C) <iostream>
- D) <cmath>
Correct Answer: B) <stdlib.h>
Output of the below code is______
int x = 5;
cout << x++;
- A) 5
- B) 6
- C) Compilation error
- D) Undefined behavior
Correct Answer: A) 5
Which of the following is not a valid storage class in C++?
- A) static
- B) constant
- C) register
- D) extern
Correct Answer: B) constant
What is the purpose of the try, catch, and throw keywords in C++?
- A) To define a loop construct
- B) To handle exceptions and errors
- C) To declare macros
- D) To define a switch-case statement
Correct Answer: B) To handle exceptions and errors
What is the size of the int data type in C++ on most modern systems?
- A) 4 bytes
- B) 8 bytes
- C) 2 bytes
- D) Depends on the system
Correct Answer: A) 4 bytes
Which data type in C++ is used to store single characters?
- A) char
- B) string
- C) byte
- D) character
Correct Answer: A) char
What is the range of values that can be stored in an unsigned short int in C++?
- A) -32768 to 32767
- B) 0 to 65535
- C) -128 to 127
- D) 0 to 255
Correct Answer: B) 0 to 65535
Which data type in C++ is used to store decimal numbers with single precision?
- A) float
- B) double
- C) long double
- D) real
Correct Answer: A) float
What is the smallest possible size of a boolean variable in C++?
- A) 1 byte
- B) 2 bytes
- C) 4 bytes
- D) Depends on the compiler
Correct Answer: A) 1 byte
Which data type in C++ is used to store true or false values?
- A) bool
- B) boolean
- C) bit
- D) binary
Correct Answer: A) bool
What is the size of the long long data type in C++?
- A) At least 4 bytes
- B) Exactly 8 bytes
- C) At least 8 bytes
- D) Depends on the compiler
Correct Answer: C) At least 8 bytes
Which data type in C++ is used to store large integer values?
- A) long
- B) int
- C) long long
- D) short
Correct Answer: C) long long
What is the maximum value that can be stored in an unsigned int in C++?
- A) 2147483647
- B) 4294967295
- C) 32767
- D) 65535
Correct Answer: B) 4294967295
Which data type in C++ is used to store single-precision floating-point numbers?
- A) float
- B) double
- C) real
- D) float32
Correct Answer: A) float
Which keyword in C++ is used to declare a variable that cannot be modified?
- A) immutable
- B) const
- C) final
- D) readonly
Correct Answer: B) const
What is the purpose of the virtual keyword in C++?
- A) To indicate a function that cannot be overridden
- B) To specify a class that cannot be inherited
- C) To enable dynamic binding and polymorphism
- D) To declare a variable with dynamic storage duration
Correct Answer: C) To enable dynamic binding and polymorphism
Which keyword in C++ is used to define a constant pointer?
- A) pointer
- B) const
- C) constant
- D) ptr
Correct Answer: B) const
What is the function of the break keyword in C++?
- A) To exit the current loop or switch statement
- B) To skip the rest of the code in a loop and continue to the next iteration
- C) To declare the end of a function
- D) To define the end of a class
Correct Answer: A) To exit the current loop or switch statement
Which keyword in C++ is used to define a base class pointer that can point to objects of derived classes?
- A) super
- B) base
- C) parent
- D) virtual
Correct Answer: B) base
What is the purpose of the static keyword in C++?
- A) To specify that a variable is accessible only within its containing function
- B) To declare a class member variable as shared among all instances of the class
- C) To allocate memory dynamically
- D) To define a function that cannot be overridden
Correct Answer: B) To declare a class member variable as shared among all instances of the class
Which keyword in C++ is used to exit from the entire program?
- A) quit
- B) end
- C) exit
- D) terminate
Correct Answer: C) exit
What does the typedef keyword do in C++?
- A) Declares a new variable type
- B) Defines a constant value
- C) Creates a reference to an existing variable
- D) Specifies a function as a template
Correct Answer: A) Declares a new variable type
What is the function of the inline keyword in C++?
- A) To specify that a function can be called recursively
- B) To define a function that is expanded in place during compilation
- C) To declare a function that can be overridden in derived classes
- D) To declare a function as a member of a class
Correct Answer: B) To define a function that is expanded in place during compilation
Which keyword in C++ is used to define a class that cannot be instantiated?
- A) static
- B) final
- C) constant
- D) abstract
Correct Answer: B) final