tailieunhanh - Integer Arithmetic In Chapter

Using Checked and Unchecked Integer Arithmetic In Chapter 2, you learned how to use binary arithmetic operators such as + and * on primitive data types such as int and double. | Using Checked and Unchecked Integer Arithmetic In Chapter 2 you learned how to use binary arithmetic operators such as and on primitive data types such as int and double. You also saw that the primitive data types have a fixed size. For example a C int is 32 bits. Because int has a fixed size you know exactly the range of value that it can hold it is -2147483648 to 2147483647. TIP If you want to determine the minimum or maximum value of int in code you can use the or fields. The fixed size of the int type creates a problem. For example what happens if you add 1 to an int whose value is currently 2147483647 The answer is that it depends on how the application is compiled. By default the C compiler generates code that allows the calculation to silently overflow. In other words you get the wrong answer. In fact the calculation wraps around to the largest negative integer value and the result generated is -2147483648. The reason for this behavior is performance integer arithmetic is a common operation in almost every program and adding the overhead of overflow checking to each integer expression could lead to very poor performance. In many cases the risk is acceptable because you know or hope that your int values won t reach their limits. If you don t like this approach you can turn on overflow checking by setting. TIP You can enable and disable overflow checking in Visual Studio 2005 by setting the project properties. On the Project menu click YourProject Properties where YourProject is the name of your project . In the project properties dialog box click the Build tab. Click the Advanced button in the lower-right corner of the page. In the Advanced Build Settings dialog box select or clear the Check for arithmetic overflow underflow check box. Regardless of how you compile an application you can use the checked and unchecked keywords to selectively turn on and off integer arithmetic overflow checking in parts of an application that you .

TÀI LIỆU LIÊN QUAN
10    127    1
6    150    1
7    127    1
5    125    1
6    127    1
6    115    1
6    122    1
6    174    1
7    122    1
crossorigin="anonymous">
Đã 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.