Explore Westonci.ca, the leading Q&A site where experts provide accurate and helpful answers to all your questions. Experience the ease of finding accurate answers to your questions from a knowledgeable community of professionals. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.

explain declaration and initialization of one and two dimensional arrays with example


Sagot :

The declaration and initialization of arrays involves creating and using the arrays

How to declare an array?

Assume the programming language is Java.

To declare and initialize an array, we make use of:

  • One dimensional array: Data-Type Array-name [] = {List of array values}
  • Two dimensional array: Data-Type Array-name [] [] = {List of array values}

Assume the array name of the one dimensional array is num, and the data type is integer.

The following can be used to declare and initialize the array to have 5 elements

int num [] = {1,2,3,4,5}

Assume the array name of the two dimensional array is num, and the data type is integer.

The following can be used to declare and initialize the array to have 2 rows and 3 columns

int num [][] = {{1,2},{3,4},{5,6}}

Read more about arrays at:

https://brainly.com/question/22364342