TAILIEUCHUNG - C++ Lab 6 Review of Variables, Formatting & Loops

We learned that a variable is a name assigned to the first byte of the necessary memory to store a value. During compile time the compiler reserves necessary memory for each variable. It may require more than one byte to store a value. The compiler needs to know the size of memory to reserve. This is why a type is always associated with a variable. In a 16-bit computer 2 bytes are used to store an integer, 4 bytes for floats, 8 bytes for double, and 1 byte for character and bool. The size of memory reserved by the compiler. | Lab 6 Review of Variables Formatting Loops By Dr. John Abraham Professor UTPA Variables We learned that a variable is a name assigned to the first byte of the necessary memory to store a value. During compile time the compiler reserves necessary memory for each variable. It may require more than one byte to store a value. The compiler needs to know the size of memory to reserve. This is why a type is always associated with a variable. In a 16-bit computer 2 bytes are used to store an integer 4 bytes for floats 8 bytes for double and 1 byte for character and bool. The size of memory reserved by the compiler you are using can be determined by the operator sizeof. For example cout sizeof x if x is an integer either a 2 or 4 will be displayed. Some of these types can be signed or unsigned. Unsigned can hold much larger number. For example in a signed integer variable the range of values are -32 768 to 32 767. In an unsigned integer this range is from 0 to 65 535. Float and double are real numbers the difference is in their precision. The major differences between integers and real numbers are as follows. 1. integers are ordinal an integer has a specific predecessor and successor. They are represented precisely in the computer in binary. Negative numbers are represented in two s complement. 2. Real numbers are not ordinal. They have decimal portions. They are represented in the computer as two portions mantissa and exponent. Real numbers cannot be represented exactly in the computer they are approximations only. Therefore two real numbers cannot be checked for equality. Truncation errors occur when two real numbers are multiplied or divided. Formatting When outputing a real number it is often necessary to indicate the number of decimal digits we want to display. When dealing with dollars there is little reason to go beyond two decimal points. We can use setprecision n which is a manipulator available from iomanip to indicate the decimal precision we require. For example

TỪ KHÓA LIÊN QUAN
Đã 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.