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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:19:15+00:00 2026-06-03T19:19:15+00:00

I cannot understand these 2 strange behaviour 1. First Behaviour I have declared a

  • 0

I cannot understand these 2 strange behaviour

1. First Behaviour

I have declared a variable like this

double[][] dd =
{
    new double[10],
    new double[10]
};

It does not give error.

But if i do like this it gives error

double[][] dd;

dd = { // Here it gives 2 errors says Invalid Expression { and ; expected 
      new double[10], 
      new double[10] //Here and in the above line it says only  
                     //assignment, call, increment....can be used as a statement
     };

Error is gone if i do this

double[][] dd;

dd = new double[][]{
                     new double[10],
                     new double[10]
                   };

Why?

2. Second Behaviour

More over it does not error if an extra comma , is put after last element of array in any of the above cases

{
 new double[10],
 new double[10], //This comma here is not given as error. Why?
};

Should that extra comma not specify that one more entity should be added after it.

  • 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-03T19:19:17+00:00Added an answer on June 3, 2026 at 7:19 pm

    Quite old docs, but still relevant. What you’re looking at are Array Initializers

    Array initializers may be specified in field declarations (Section 10.4), local variable declarations (Section 8.5.1), and array creation expressions (Section 7.5.10.2).

    Note, it doesn’t say that they’re available in assignment statements, which is what you’re attempting with your first error.


    To your second question, the reason why the extra , is allowed is convenience – it’s especially useful if code is being generated programmatically if you don’t have to special case the first or last item. You’ll find similar syntax in e.g. enum declarations.

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

Sidebar

Related Questions

I cannot understand why this throws undefined reference to `floor' : double curr_time =
I cannot understand this query? select @:vfOutBalance+@:vfHSSubTotal+@3+orpartpayment,@:vfOutBalance+@:vfHSSubTotal from or_equip_upgrd_id what does @3 mean?
I cannot understand why my compiler (MSVC++2010) doesn't like this code: // get_sum(filename as
I have been trying to understand why I cannot access these links from my
For reasons I cannot understand, the people who supply my tables do not have
I cannot understand why the code below is giving me this error in firebug
I cannot understand the Java memory usage. I have an application which is executed
I cannot understand why I am getting deadlock in this simple sample.What is wrong
I still cannot understand what does it mean to return an object in a
I have a bit of a strange question. First let me tell you i

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.