Reflection: ArrayReview
I, Summary
Array types in C are traditionally of a fixed, static size specified at compile time.
dataType arrayIdentifier[ size ] = { value, ... , value };
I. Re-code again the example in the clip
II. Implement functions
1. Nhập vào kích thước và các phần tử của một mảng một chiều
void nhap(int *n, int mang[])
2. Copy một mảng sang một mảng khác
void copy(int nguon[], int dich[], int n)
3. tìm kiếm k trong mảng, không có trả về -1, có trả về chi so đầu tiên
int tim(int mang[], int n, int k)
4. In danh sách vị trí của các phần tử có giá trị bằng phần tử nhỏ nhất
void nhonhat(int mang[], int n)
5. Nhân đôi giá trị của các phần tử ở vị trí lẻ
void nhandoi(int mang[], int n)
III, Some of my thoughts
By only passing the address of the array, we avoid copying the array, which may be a rather expensive operation. When I used array, it's so convenient. I don't use much variables because I can use array with index, it's easy-to-use. Thanks for using array and function, I can code faster and faster.
Array types in C are traditionally of a fixed, static size specified at compile time.
dataType arrayIdentifier[ size ] = { value, ... , value };
The syntax of a function call that passes an array is
functionIdentifier ( arrayIdentifier, ... )
The syntax of a function header that receives an array address is
dataType functionIdentifier ( dataType arrayIdentifier [ ], ... )
II, Applied to solve problemsThe syntax of a function header that receives an array address is
dataType functionIdentifier ( dataType arrayIdentifier [ ], ... )
I. Re-code again the example in the clip
This is my result:
1. Nhập vào kích thước và các phần tử của một mảng một chiều
void nhap(int *n, int mang[])
2. Copy một mảng sang một mảng khác
void copy(int nguon[], int dich[], int n)
3. tìm kiếm k trong mảng, không có trả về -1, có trả về chi so đầu tiên
int tim(int mang[], int n, int k)
4. In danh sách vị trí của các phần tử có giá trị bằng phần tử nhỏ nhất
void nhonhat(int mang[], int n)
5. Nhân đôi giá trị của các phần tử ở vị trí lẻ
void nhandoi(int mang[], int n)
III, Some of my thoughts
By only passing the address of the array, we avoid copying the array, which may be a rather expensive operation. When I used array, it's so convenient. I don't use much variables because I can use array with index, it's easy-to-use. Thanks for using array and function, I can code faster and faster.
Comments
Post a Comment