Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3980788
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:19:57+00:00 2026-05-20T05:19:57+00:00

There is this little trick question that some interviewers like to ask for whatever

  • 0

There is this little trick question that some interviewers like to ask for whatever reason:

int arr[] = {1, 2, 3};
2[arr] = 5; // does this line compile?
assert(arr[2] == 5); // does this assertion fail?

From what I can understand, a[b] gets converted to *(a + b) and since addition is commutative, it doesn’t really matter their order, so 2[a] is really *(2 + a) and that works fine.

Is this guaranteed to work by C and/or C++’s specs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:19:57+00:00Added an answer on May 20, 2026 at 5:19 am

    Yes. 6.5.2.1 paragraph 1 (C99 standard) describes the arguments to the [] operator:

    One of the expressions shall have type “pointer to object type“, the other expression shall have integer type, and the result has type “type“.

    6.5.2.1 paragraph 2 (emphasis added):

    A postfix expression followed by an expression in square brackets [] is a subscripted
    designation of an element of an array object. The definition of the subscript operator []
    is that E1[E2] is identical to (*((E1)+(E2)))
    . Because of the conversion rules that
    apply to the binary + operator, if E1 is an array object (equivalently, a pointer to the
    initial element of an array object) and E2 is an integer, E1[E2] designates the E2-th
    element of E1 (counting from zero).

    It says nothing requiring the order of the arguments to [] to be sane.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a little out there but I have a customer object coming back
There is previous little on the google on this subject other than people asking
There's this program, pdftotext, that can convert a pdf file to a text file.
There's a very simple jquery plugin: autotextarea. I'd like to teach it one little
Hey guys, this question might be a little weird worded but I was looking
I got this project, where there this error keeps occurring and its not on
There is this example code, but then it starts talking about millisecond / nanosecond
There's this Excel file I want users to be able to download from my
There is this option available in Visual Studio 2008. Is there a similar option
Before I start, I know there is this post and it doesn't answer my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.