Data Structures and Algorithms – C++ Implementation
BK
TP.HCM
Ho Chi Minh City University of Technology Faculty of Computer Science and Engineering
BK
TP.HCM
Data Structures and Algorithms – C++ Implementation
Huỳnh T n t
Email: htdat@cse.hcmut.edu.vn Home Page: http://www.cse.hcmut.edu.vn/~htdat/
.Pointer in C++
Declaration Node *ptr; Create an object ptr = new Node(); A pointer usage printf(“Data in node: %d”, ptr-data); Destroy an object delete ptr; NULL pointer ptr = NULL;
??? ptr
ptr
??? ptr
ptr
Faculty of Computer Science and Engineering – HCMUT Slide 2
.Pointer in C++
Be careful in these cases: Before
ptr1
Before
ptr1
ptr2 ptr1 = ptr2;
ptr2 delete ptr1; ptr1 = NULL;
Garbage
After
ptr1
After
ptr1
ptr2
ptr2
Dangling reference problem Slide 3
Faculty of Computer Science and Engineering – HCMUT
.Parameter Passing Techniques
void func(int* a, int* b){ int *t; t = a; a = b; b = t; } void func(int* &a, int* &b){ int *t; t = a; a = b; b = t; } void main() { int *p1 = new int; *p1 = 10; int *p2 = new int;
Xin lỗi bạn không thể down load tài liệu này. Bạn có thể xem tài liệu trực tuyến trên website hoặc liên hệ thư viện trường để được hướng dẫn. Cảm ơn bạn đã sử dụng dịch vụ của chúng tôi.
Bạn vui lòng tham khảo thỏa thuận sử dụng của thư viện số.
- Xin lỗi, bạn khồng thể download tài liệu này. Bạn vui lòng liên hệ trực tiếp thư viện trường để được cấp lại tài khoản để download được tài liệu này.