Array in C++ Array in C++ MCQ Details
MCQ Practice Single Best Answer Topic: Array in C++

Q What happens if you access an array index outside its size in C++?

Question ID
#24495
Subchapter
Array in C++
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A Compiler error
  • B Runtime error always
  • C Program stops immediately
  • D Undefined behavior
Correct Answer: D

Explanation

In C++, accessing an array index outside its declared size does not automatically give a compiler error or a guaranteed runtime error.

Instead, it results in undefined behavior.

This means:

  • The program may print a garbage value

  • It may crash

  • Or it may seem to work incorrectly

  • The behavior can vary from system to system

C++ does not perform bounds checking on arrays.

Correct Answer: D) Undefined behavior

Description:
Accessing an array index beyond its size leads to unpredictable results, which is called undefined behavior in C++.

Share This Question

Share this MCQ with your friends or study group.