Lecture note Data visualization - Chapter 11

This chapter presents the following content: Stale pointers and double delete, reference variables, reference type vs pointer type, structures, pointers to structures, exogenous vs indigenous data, shallow vs deep copying, linked lists, common errors. | Lecture 11 Recap Stale Pointers and Double Delete Reference Variables Reference Type vs Pointer Type Structures Pointers to Structures Exogenous vs Indigenous Data Shallow vs Deep Copying Linked Lists Common Errors Selective Questions from Exercise Q: Name and illustrate five operations that can be applied to pointers Answer: Pointers can be declared and initialized They can be assigned to point at an object They can be dereferenced They can be involved in arithmetic The address-of operator can be applied to a pointer in the same manner as any other object Q: Consider int a, b; int *ptr; / / A pointer int **ptrPtr; / / A pointer to a pointer ptr = &a; ptr Ptr = &ptr; a. Is this code legal? Answer: Yes b. What are the values of * ptr and * * ptrPtr ? Answer: Both have the same value as A Continued . c. Using no other objects besides those already declared, how can you alter ptrPtr so that it points at a pointer to b without directly touching ptr ? Answer: *ptrPtr=&b d. Is the . | Lecture 11 Recap Stale Pointers and Double Delete Reference Variables Reference Type vs Pointer Type Structures Pointers to Structures Exogenous vs Indigenous Data Shallow vs Deep Copying Linked Lists Common Errors Selective Questions from Exercise Q: Name and illustrate five operations that can be applied to pointers Answer: Pointers can be declared and initialized They can be assigned to point at an object They can be dereferenced They can be involved in arithmetic The address-of operator can be applied to a pointer in the same manner as any other object Q: Consider int a, b; int *ptr; / / A pointer int **ptrPtr; / / A pointer to a pointer ptr = &a; ptr Ptr = &ptr; a. Is this code legal? Answer: Yes b. What are the values of * ptr and * * ptrPtr ? Answer: Both have the same value as A Continued . c. Using no other objects besides those already declared, how can you alter ptrPtr so that it points at a pointer to b without directly touching ptr ? Answer: *ptrPtr=&b d. Is the following statement legal? ptrPtr = ptr ; Answer: No; these objects have different types. Q: a. Is *&x always equal to x? If not, give an example. Answer: Yes, as long as x is an object b. Is & *x always equal to x? If not, give an example. Answer: No, because x might not be a pointer Q: Is the following code legal? Why or why not? int a = 3; const int & b = a; Answer: This is perfectly legal. However if the const is moved from the second declaration to the first, then the declaration and initialization of b would be illegal. Q: What is wrong with omitting spacing in *x/ * y? Answer: /* begins a comment. Chapter 2 Objects and Classes Introduction In this chapter we will study how C++ uses the class to achieve encapsulation and information hiding; how classes are implemented; and several examples of classes, including classes used to manipulate rational numbers and strings Object-Oriented Programming Object-oriented programming appears to be emerging as the dominant paradigm At the heart of .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.