-1

I know that you can initialize an array like this.

int[] a1=new int[2]{4,5};

or like this and then assign the values manually.

int[] a1=new int[2];

or like this

int[] a2={45,45};

Since Arrays are implemented as objects and the 'new' keyword allocates space for the object in the memory, I am wondering how is the memory allocated when initializing an array without the 'new' keyword(int[ ] a2={45,45};)?

Eric Movsessian
  • 488
  • 1
  • 11

2 Answers2

0

It's just syntactic sugar, the compiler still outputs the same newarr cil instruction.

Blindy
  • 65,249
  • 10
  • 91
  • 131
0

I believe it should just be the same thing. Lots of programming languages have different syntax shortcuts for the same action, so while they look like different things to us, the same stuff comes out of the compiler/interpreter under the hood.

Pixelz22
  • 31
  • 4