is usually chosen to be the most efficient data type on the underlying hardware

Is usually chosen to be the most efficient data type

This preview shows page 10 - 17 out of 38 pages.

is usually chosen to be the most efficient data type on the underlying hardware. The size of an int depends on the machine and the compiler On PCs it is normally 16 or 32 bits In Microsoft Visual C++ 2.0 and later it is 32 bits Other integers object types short : typically uses less bits long : typically uses more bits sizeof( short ) sizeof( int ) sizeof( long ) Signed and unsigned integer object type Signed integers are represented in two’s-complement form. The most- significant bit holds the sign: 1 for negative, 0 for positive and zero. Different types allow programmers to use resources more efficiently Standard arithmetic and relational operations are available for these types
Image of page 10
Integer Constants Integer Constants Integer constants are positive or negative whole numbers Integer constant forms Decimal Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Octal (base 8) Digits 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal (base 16) Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Examples 234 31 102L 989L 056 031 077L 010L 0889 ( illegal) 0x2A 0x45 0xffL 0xA1eL The range of represented number of integer object types: 16 bits integer: signed: –32768 ~ 32768 unsigned: 0 ~ 65535 32 bits integer: signed: –2147483647 ~ 2147483647 unsigned: 0 ~ 4294967295 L or l indicates long integer
Image of page 11
Character Object Types Character Object Types Character type char char is related to the integer types Characters are encoded using a scheme where an integer represents a particular character ASCII is the dominant encoding scheme Examples ' ' encoded as 32 '+' encoded as 43 'A' encoded as 65 'Z' encoded as 90 'a' encoded as 97 'z' encoded as 122 See appendix A for the complete ASCII character set We can always assume that the following relationships hold. ’a’ < ’b’ < ’c’ < … < ’z’ ’A’ < ’B’ < ’C’ < … < ’Z’ ’0’ < ’1’ < ’2’ < … < ’9’
Image of page 12
Character Object Types Character Object Types Arithmetic and relational operations are defined for characters types 'a' < 'b' is true '4' > '3' is true '6' <= '2' is false 'a'+1='b' Also in ASCII character encode set 'a'+1 = 'b' 'A'+1 = 'B' '2'+1 = '3' '9'+1 = ???
Image of page 13
Character Constants Character Constants Explicit (literal) characters within single quotes 'a','D','*' What’s the value of 'abcd'? Special characters - delineated by a backslash \ Two character sequences (escape codes) Some important special escape codes \t denotes a tab \n denotes a new line \\ denotes a backslash \' denotes a single quote \" denotes a double quote '\t' is the explicit tab character, '\n' is the explicit new line character, and so on
Image of page 14
C++ Character escape code C++ Character escape code Character name ASCII name ASCII Value (Decimal) Escape Sequence New line NL 10 \n Horizontal tab HT 9 \t Vertical tab VT 11 \v Backspace BS 8 \b Carriage return CR 13 \r Form feed FF 12 \f Alert BEL 7 \a Backslash \ 92 \\ Question mark ? 63 \? Single quotation mark ' 39 \' Double quotation mark " 34 \" Octal number ooo \ ooo Hexadecimal number hhh \x hhh Null character NUL 0 \0
Image of page 15
Literal String Constants Literal String Constants A literal string constant is a sequence of zero or more characters enclosed in double quotes "We are even loonier than you think" "Rust never sleeps\n" "" Not a fundamental type Storage of string literal == number of characters + 1 ”Hello World!” H e l l o
Image of page 16
Image of page 17

You've reached the end of your free preview.

Want to read all 38 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes