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

  • SEARCH
  • Home
  • 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

On this page there is a list of footer links that have a little
Why only one overload throws this exception? Little update: I understand that there was
So, this one seems to be a little tricky. There's an image map with
This might be a little bit picky, but in the iPad SplitViewController setup, there
There is this output of objdump on some object file: $ objdump -h main.o
There is this way, of course: OuterClass.this . But that's very clumsy. Ideally, there'd
There was this problem that has been asked about implementing a load byte into
There's a very simple jquery plugin: autotextarea. I'd like to teach it one little
I'm doing some math with really big numbers (I'm using Python, but this question
It seems there are some very good resources on my question - at least

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.