C++ language › Array in C++ › Question #24495
Single Choice Moderate

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

ID: #24495 Array in C++ 58 views
Question Info
#24495Q ID
ModerateDifficulty
Array in C++Topic

Choose the Best Option

Click any option to instantly check if you're correct.

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

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++.

Today: 0 answered · 0 correct
Save progress
Free account

Want to remember what you got wrong?

Create a free account in seconds to track your score, revisit mistakes and continue C++ language where you left off.

  • Save your progress & streak
  • Topic-wise quizzes & scores
  • Bookmark tricky questions
  • Printable MCQ sets
Practice smarterFree account · save progress
Sign up free

Share This Question

Challenge a friend or share with your study group.