Computer programming mcqs

computer programming mcqs with answers pdf
computer programming mcqs with answers pdf

What does the static keyword indicate when used with a class member variable in C++?

  1. A) It specifies that the variable is shared among all instances of the class.
  2. B) It declares the variable as constant.
  3. C) It denotes that the variable is accessible only within its containing function.
  4. 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?

  1. A) Queue computer programming mcqs with answers pdf
  2. B) Array
  3. C) Stack
  4. 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++?

  1. A) It indicates that the function cannot be overridden in derived classes.
  2. B) It enables dynamic binding and late binding.
  3. C) It specifies that the function is pure virtual and must be overridden in derived classes.
  4. 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?

  1. A) &  computer programming mcqs with answers pdf
  2. B) *
  3. C) ->
  4. D) ::

Correct Answer: B) *

 What does the new operator return if memory allocation fails in C++?

  1. A) nullptr
  2. B) -1
  3. C) 0  computer programming mcqs with answers pdf
  4. D) It throws an exception

Correct Answer: A) nullptr

Which of the following correctly declares a pointer to a function in C++?

  1. A) int (*ptr)();
  2. B) int *ptr();
  3. C) int *ptr;
  4. D) int ptr();

Correct Answer: A) int (*ptr)();

In C++, which header file should be included to use the exit() function?

  1. A) <stdio.h>
  2. B) <stdlib.h>
  3. C) <iostream>
  4. D) <cmath>

Correct Answer: B) <stdlib.h>

Output of the below code is______

int x = 5;

cout << x++;

  1. A) 5
  2. B) 6
  3. C) Compilation error
  4. D) Undefined behavior

Correct Answer: A) 5

Which of the following is not a valid storage class in C++?

  1. A) static
  2. B) constant
  3. C) register
  4. D) extern

Correct Answer: B) constant

What is the purpose of the try, catch, and throw keywords in C++?

  1. A) To define a loop construct
  2. B) To handle exceptions and errors
  3. C) To declare macros
  4. 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?

  1. A) 4 bytes
  2. B) 8 bytes
  3. C) 2 bytes
  4. D) Depends on the system

Correct Answer: A) 4 bytes

Which data type in C++ is used to store single characters?

  1. A) char
  2. B) string
  3. C) byte
  4. D) character

Correct Answer: A) char

What is the range of values that can be stored in an unsigned short int in C++?

  1. A) -32768 to 32767
  2. B) 0 to 65535
  3. C) -128 to 127
  4. D) 0 to 255

Correct Answer: B) 0 to 65535

Which data type in C++ is used to store decimal numbers with single precision?

  1. A) float
  2. B) double
  3. C) long double
  4. D) real

Correct Answer: A) float

What is the smallest possible size of a boolean variable in C++?

  1. A) 1 byte
  2. B) 2 bytes
  3. C) 4 bytes
  4. D) Depends on the compiler

Correct Answer: A) 1 byte

Which data type in C++ is used to store true or false values?

  1. A) bool
  2. B) boolean
  3. C) bit
  4. D) binary

Correct Answer: A) bool

What is the size of the long long data type in C++?

  1. A) At least 4 bytes
  2. B) Exactly 8 bytes
  3. C) At least 8 bytes
  4. D) Depends on the compiler

Correct Answer: C) At least 8 bytes

Which data type in C++ is used to store large integer values?

  1. A) long
  2. B) int
  3. C) long long
  4. D) short

Correct Answer: C) long long

What is the maximum value that can be stored in an unsigned int in C++?

  1. A) 2147483647
  2. B) 4294967295
  3. C) 32767
  4. D) 65535

Correct Answer: B) 4294967295

Which data type in C++ is used to store single-precision floating-point numbers?

  1. A) float
  2. B) double
  3. C) real
  4. D) float32

Correct Answer: A) float

Which keyword in C++ is used to declare a variable that cannot be modified?

  1. A) immutable
  2. B) const
  3. C) final
  4. D) readonly

Correct Answer: B) const

What is the purpose of the virtual keyword in C++?

  1. A) To indicate a function that cannot be overridden
  2. B) To specify a class that cannot be inherited
  3. C) To enable dynamic binding and polymorphism
  4. 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?

  1. A) pointer
  2. B) const
  3. C) constant
  4. D) ptr

Correct Answer: B) const

What is the function of the break keyword in C++?

  1. A) To exit the current loop or switch statement
  2. B) To skip the rest of the code in a loop and continue to the next iteration
  3. C) To declare the end of a function
  4. 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?

  1. A) super
  2. B) base
  3. C) parent
  4. D) virtual

Correct Answer: B) base

What is the purpose of the static keyword in C++?

  1. A) To specify that a variable is accessible only within its containing function
  2. B) To declare a class member variable as shared among all instances of the class
  3. C) To allocate memory dynamically
  4. 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?

  1. A) quit
  2. B) end
  3. C) exit
  4. D) terminate

Correct Answer: C) exit

What does the typedef keyword do in C++?

  1. A) Declares a new variable type
  2. B) Defines a constant value
  3. C) Creates a reference to an existing variable
  4. 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++?

  1. A) To specify that a function can be called recursively
  2. B) To define a function that is expanded in place during compilation
  3. C) To declare a function that can be overridden in derived classes
  4. 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?

  1. A) static
  2. B) final
  3. C) constant
  4. D) abstract

Correct Answer: B) final

computer programming mcqs with answers pdf
computer programming mcqs with answers pdf
computer programming mcqs with answers pdf
computer programming mcqs with answers pdf
computer programming mcqs with answers pdf

Leave a Comment