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 9144355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:14:57+00:00 2026-06-17T10:14:57+00:00

Why does int a[x,y] convert into a[y] , since comma operator operates left to

  • 0

Why does int a[x,y] convert into a[y], since comma operator operates left to right? I would expect a[(x,y)], since inner operation will finish first. But in the first one it is supposed to take the first argument.

I’m not planning to use the comma operator for array initialization, just asking why this happens.

I read it in a book, and I’m confused.

Update:

Wikipedia says:

 i = a, b, c;            // stores a into i 
 i = (a, b, c);          // stores c into i   

So as first line of code says in the array the first value must be assigned to the array. Note: I’m not actually planning to use this. I’m just asking. I’m learning C++ and I read in a book that in an array declaration a[y,x]; so it should be a[y], x; not a[x]. Why does the compiler do this?

  • 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-06-17T10:14:58+00:00Added an answer on June 17, 2026 at 10:14 am

    The comma operator , is also known as the “forget” operator. It does the following:

    1. Completely evaluate the left operand
    2. Forget its value
    3. Completely evaluate the right operand
    4. Use value of right operand as value of entire operator expression.

    So in your case, it behaves just as it should. a[x, y] first evaluates x, then discards its value, then uses the value of y as the value of the entire expression (the one in brackets).

    EDIT

    Regarding your edit with Wikipedia. Note that the precedence of , is less than that of =. In other words,

    i = a, b, c;
    

    is interpreted as

    (i = a), b, c;
    

    That’s why a is copied into i. However, the result of the entire expression will still be c.

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

Sidebar

Related Questions

Why does the statement (int)84 throw an exception and Convert.ToInt32(84) does not throw an
How does one convert from an int or a decimal to a float in
I have a little snag , I ought to Convert my Stopwatch into Int
Why does implicit operator have problems when I try to convert the return type
I have the following function that will convert a string into a numeric data
I want to convert QStrings into filenames. Since I'd like the filename to look
Does (int)myDouble ever differ from (int)Math.Truncate(myDouble) ? Is there any reason I should prefer
Does int a = int(); necessarily give me a zero? How about if int
Does setWidth(int pixels) use device independent pixel or physical pixel as unit? For example,
What does sizeof (int) * p semantically mean? Is it: 1. sizeof( (int) *p

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.