Chapter 2: Arrays and Pointers
1
Lecturer: PhD. DO Thi Ngoc Diep
SCHOOL OF ELECTRICAL AND ELECTRONIC ENGINEERING
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY
2
Content
2.1. Array
2.1.1. Array variable types
2.1.2. Multidimensional arrays
2.1.3. Strings
2.2. Pointers
2.2.1. Pointer variable types
2.2.2. Pointers vs arrays
2.2.3. Dynamic Memory allocation
3
2.1. Array
2.1.1. Array variable types
Used to store a finite set of elements
of the same type (primitive or object)
adjacent to each other in memory
Each array has a name
The elements are numbered
Array name
Index
Declaration and Initialization
Specify number of dimensions, size of array, type of elements
Declaration (1D array)
type array_name [N] ;
type array_name [N] = {v1,v2,…,vn};
type array_name [] = {v1,v2,…,vn};
v1,v2,…,vn:initial values for elements
int a[10];