Course Hero Logo

Former in this case the effect is that the string

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 7 - 9 out of 29 pages.

former. In this case, the effect is that the string "Hello World\n" is sent to cout, causing it to beprinted on the computer monitor screen.5This brace marks the end of the body of main.VariablesAvariableis a symbol that is assigned a type and a memory area of the correct size.A variableis a symbolic name for a memory location in which data can bestored and subsequently recalled.Variables are used for holding data values sothat they can be utilized in various computations ina program. All variableshave two important attributes:· Atypewhich is established when the variable is defined (e.g., integer, real, character). Oncedefined, the type of a C++ variable cannot be changed.· Avaluewhich can be changed by assigning a new value to the variable. The kind of values avariable can assume depends on its type. For example, an integer variable can only take integervalues (e.g., 2, 100, -12).Integer NumbersAninteger variablemay be defined to be of type short, int, or long. The only difference is thatan int uses more or at least the same number of bytes as a short, and a long uses more or at leastthe same number of bytes as an int.For example, on the author’s PC, a short uses 2 bytes, an int also 2 bytes, and a long 4 bytes.short age = 20;int salary = 65000;long price = 4500000;By default, an integer variable is assumed to be signed (i.e., have a signed representation so thatit can assume positive as well as negative values).However, an integer can be defined to be unsigned by using the keyword unsigned in itsdefinition. The keyword signed is also allowed but is redundant.
unsigned short age = 20;unsigned int salary = 65000;unsigned longprice = 4500000;Aliteral integer(e.g., 1984) is always assumed to be of type int, unless it has an L or l suffix, inwhich case it is treated as a long. Also, a literal integer can be specified to be unsigned using thesuffix U or u. For example: 1984L 1984l 1984U 1984u 1984LU 1984ulLiteral integers can be expressed in decimal, octal, and hexadecimal notations. The decimalnotation is the one we have been using so far. An integer is taken to be octal if it is preceded by azero (0), and hexadecimal if it is preceded by a 0x or 0X. For example:92 // decimal0134 // equivalent octal0x5C // equivalent hexadecimalOctal numbers use the base 8, and can therefore only use the digits 0-7.Hexadecimal numbers use the base 16, and therefore use the letter A-F to represent, respectively,10-15. Octal and hexadecimal numbers are calculated as follows:0134 = 1 × 82 + 3 × 81 + 4 × 80 = 64 + 24 + 4 = 92Real NumbersAreal variablemay be defined to be of type float or double. The latter uses more bytes andtherefore offers a greater range and accuracy for representing real numbers. For example, on theauthor’s PC, a float uses 4 and a double uses 8 bytes.float interestRate = 0.06;double pi = 3.141592654;Aliteral real(e.g., 0.06) is always assumed to be of type double, unless it has an F or f suffix, inwhich case it is treated as a float, or an L or l suffix, in which case it is treated as a long double.The latter uses more bytes than a double for better accuracy (e.g., 10 bytes on the author’s PC).For example:0.06F 0.06f 3.141592654L 3.141592654l

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 29 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
N/A

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture