Danh mục

Lecture Data Structures & Algorithms: Chapter 1

Số trang: 22      Loại file: pptx      Dung lượng: 644.97 KB      Lượt xem: 17      Lượt tải: 0    
Thư viện của tui

Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Lecture Data Structures & Algorithms: Chapter 1 (C-Language) presented address, pointers, arrays, address of each element in an array, accessing & manipulating an array using pointers, another case of manipulating an array using pointers, two-dimensional array, pointer arrays, structures, structure pointers.
Nội dung trích xuất từ tài liệu:
Lecture Data Structures & Algorithms: Chapter 1 DONG NAI UNIVERSITY OF TECHNOLOGYData Structures & Algorithms DONG NAI UNIVERSITY OF TECHNOLOGYC-Language DONG NAI UNIVERSITY OF TECHNOLOGY1. ADDRESS2. POINTERS3. ARRAYS4. ADDRESS OF EACH ELEMENT IN AN ARRAY5. ACCESSING & MANIPULATING AN ARRAY USING POINTERS6. ANOTHER CASE OF MANIPULATING AN ARRAY USING POINTERS7. TWO-DIMENSIONAL ARRAY8. POINTER ARRAYS9. STRUCTURES10. STRUCTURE POINTERS DONG NAI UNIVERSITY OF TECHNOLOGY 1.ADDRESS For every variable there are two attributes: address and valueIn memory with address 2: valueDaveIn memory with address 5: value: 95.5 cout DONG NAI UNIVERSITY OF TECHNOLOGY 2. POINTERS 1. is a variable whose value is also an address. 2. A pointer to an integer is a variable that can store the address of that integeria: value of variable&ia: address of ia*ia means you are printing the value at thelocation specified by ia DONG NAI UNIVERSITY OF TECHNOLOGYint i; //Aint * ia; //Bcout DONG NAI UNIVERSITY OF TECHNOLOGY Points to Remember:• Pointers give a facility to access the value of a variable indirectly.• You can define a pointer by including a * before the name of the variable.• You can get the address where a variable is stored by using &. 3. ARRAYS DONG NAI UNIVERSITY OF TECHNOLOGYa. An array is a data structureb. used to process multiple elements with the same data type when a number of such elements are known.c. An array is a composite data structure; that means it had to be constructed from basic data types such as array integers. int M[10]; for(int i = 0;i DONG NAI UNIVERSITY OF TECHNOLOGY4. ADDRESS OF EACH ELEMENT IN AN ARRAY - Each element of the array has a memory address.void printdetail(int M[]){ for(int i = 0;i DONG NAI UNIVERSITY OF TECHNOLOGY5. ACCESSING & MANIPULATING AN ARRAY USING POINTERS – You can access an array element by using a pointer. – If an array stores integers -> use a pointer to integer to access array elements. DONG NAI UNIVERSITY OF TECHNOLOGYvoid printarr_usingpointer(int M[]){ int *pi; pi=M; for(int i=0;i DONG NAI UNIVERSITY OF TECHNOLOGY6. ANOTHER CASE OF MANIPULATING AN ARRAY USING POINTERS The array limit is a pointer constant : cannot change its value in the program. int a[5]; int *b; a=b; //error b=a; //OK DONG NAI UNIVERSITY OF TECHNOLOGYvoid printarr_usingpointer(int M[]){for(int i=0;i DONG NAI UNIVERSITY OF TECHNOLOGY7. TWO-DIMENSIONAL ARRAYint M[3][4]; 7 2 9 0 9 5 4 1 8 0 3 6 DONG NAI UNIVERSITY OF TECHNOLOGY Column 0 Column 1 Column 2 Column 3 M[0][0] M[0][1] M[0][2] M[0][3]Row 0 7 2 9 0 M[1][0] M[1][1] M[1][2] M[1][3]Row 1 9 5 4 1 M[2][0] M[2][1] M[2][2] M[2][3]Row 2 8 0 3 6 Column index (or subscript) Row index (or subscript) Array name DONG NAI UNIVERSITY OF TECHNOLOGYvoid printarr_usingpointer(int M[][4]){ for(int i=0;i DONG NAI UNIVERSITY OF TECHNOLOGYfor(int i=0;i DONG NAI UNIVERSITY OF TECHNOLOGY 8. POINTER ARRAYSl You can define a pointer array (similarly to an array of integers).l In the pointer array, the array elements store the pointer that points to integer values.void main() DONG NAI UNIVERSITY OF TECHNOLOGY void printarr(int *M[]){ {int *M[5]; cout DONG NAI UNIVERSITY OF TECHNOLOGY 9. STRUCTURES• Structures are used when you want to process data of multiple data types• But you still want to refer to the data as a single entity• Access data: structurename.membername

Tài liệu được xem nhiều:

Gợi ý tài liệu liên quan: