TAILIEUCHUNG - Microsoft Visual C# 2010 Step by Step (P5)

Tham khảo sách 'microsoft visual c# 2010 step by step (p5)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 170 Part II Understanding the C Language You can access and modify the value held in the variable i through the pointer variable pi like this pi 100 This code updates the value of the variable i to 100 because pi points to the same memory location as the variable i. One of the main problems that developers learning C and C have is understanding the syntax used by pointers. The operator has at least two meanings in addition to being the arithmetic multiplication operator and there is often great confusion about when to use rather than . The other issue with pointers is that it is easy to point somewhere invalid or to forget to point somewhere at all and then try to reference the data pointed to. The result will be either garbage or a program that fails with an error because the operating system detects an attempt to access an illegal address in memory. There is also a whole range of security flaws in many existing systems resulting from the mismanagement of pointers some environments not Microsoft Windows fail to enforce checks that a pointer does not refer to memory that belongs to another process opening up the possibility that confidential data could be compromised. Reference variables were added to C to avoid all these problems. If you really want to you can continue to use pointers in C but you must mark the code as unsafe. The unsafe keyword can be used to mark a block of code or an entire method as shown here public static void Main string args int x 99 y 100 unsafe swap x y x is now 0 y is now 1 x y public static unsafe void swap int a int b int temp temp a a b b temp When you compile programs containing unsafe code you must specify the unsafe option. Unsafe code also has a bearing on how memory is managed objects created in unsafe code are said to be unmanaged. We discuss this issue in more detail in Chapter 14. Chapter 8 Understanding Values and References 171 In this chapter you learned about some important differences between value .

Đã 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.