LearnFrenzy
Sign in Take a free test

Arrays · Array Basics MCQ · Question 7

Is i[a] the same as a[i] in C? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 7 Back to Exercise

For an array a and an int i, what is i[a]?

  • A A compile error
  • B The same element as a[i] Correct
  • C The address of a[i]
  • D Undefined behaviour
Correct Answer: Option B

The standard defines E1[E2] as *((E1) + (E2)). Addition is commutative, so i[a] is *(i + a), exactly a[i]. Legal, but never write it in real code.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links