Uploaded by Taha Talat

array

advertisement
Data Structures
SWE
Hello 😍 world
Agenda
>> array
>> pointer
>> struct
>> class
array
An array is a series of elements of the same type placed in contiguous
memory locations that can be individually referenced by adding an
index to a unique identifier.
int foo [5];
Array initialization
int foo [] = { 16, 2, 77, 40, 12071 };
int baz [5] = { };
Access Array elements
int foo [5];
Multidimension Array
2D
int jimmy [3][5];
Multidimension Array
3D
int rubik [9][3][3];
http://games.xubala.com/rubik/index.html
Array
Dynamic allocation
int * foo;
foo = new int [5];
In this case, the system dynamically allocates space for five elements of type int and
returns a pointer to the first element of the sequence, which is assigned to foo (a
pointer). Therefore, foo now points to a valid block of memory with space for five
elements of type int.
Download