140 likes | 341 Views
Array. Cs212: DataStructures Lab 2. Array. Group of contiguous memory locations Each memory location has same name Each memory location has same type. a is the name of this array . Array index or subscript. Declaring , Allocating an initialize Arrays.
E N D
Array Cs212: DataStructures Lab 2
Array • Group of contiguous memory locations • Each memory location has same name • Each memory location has same type a is the name of this array Array index or subscript
Declaring , Allocating an initialize Arrays • Declare array of zero (JAVA ) 1- Default Each int is initialized to 0 by default
Declare array of zero (c++) 1- using Loop 2- Or we can use initializer List OUT PUT
Initialize the array with different value using initializer list (C++) (JAVA) Output
Initialize the array with user inputs (C++) Output
Ex 1: • Calculate value stored in each array element • Initialize elements of 10-element array to even integers start the even number from 2.
Answer: (java)
Answer: (C++) Output
EX2: • Array elements • Can represent a series of values • We can sum these values
Answer: (C++) Output
Answer: (java)