CS 206 C2 Lexical Elements, Operators and the C System s1

CS 206 C2 Lexical Elements, Operators and the C System s1

<p>CS 206 – C3 – Fundamental Data Types</p><p>6.1 Storage, Compilers, Machine Instructions, Variables, Constants, etc.</p><p>6.2 The Fundamental Data Types</p><p>6.3 Characters and the Data Type char</p><p>Positional Notation, Bits, Bit Strings, Bytes, Collating Sequence, ASCII, EBCDIC, etc.</p><p>See p 609, App E.</p><p>6.4 The Data Type int 2’s Complement, +/- integers, unsigned integers, Half Words, Words, etc.</p><p>Hex/Octal Constants – 0377 (O) or 0x1A (H). Used to set bit strings…</p><p>6.5 The Integral Types short, long and unsigned short => typically 2 bytes (half word) (machine/compiler dependent) long => typically 4 bytes (word) (machine/compiler dependent) unsigned => typically 4 bytes (word) (machine/compiler dependent)</p><p>Arithmetic on unsigned ints is logical.</p><p>6.6 The Floating Types float vs int… float => sign, exponent, significant digits, typically 4 bytes double => typically 8 bytes (machine/compiler dependent) long double => typically 8 bytes (machine/compiler dependent)</p><p>Range vs Accuracy…</p><p>6.7 sizeof Operator</p><p>Guaranteed configurations…</p><p>Note: sizeof is an operator… if sizeof is applied to a type, parentheses are required. If not, parentheses are optional, i.e., sizeof(a + b + 7.7) .eqv. sizeof a + b + 7.7</p><p>Code to determine data type sizes…</p><p>6.8 Mathematical Functions</p><p>Mathematics library contains sqrt(), pow(), exp(), log(), sin(), cos(), tan(), etc.</p><p>Arguments are type double, function returns are type double.</p><p>Trig function arguments are in radians.</p><p>Example Code… 6.9 Conversions and Casts</p><p>Integral Promotion</p><p>Def: If all data types in an expression can be represented by an int, the expression value is converted to an int. Otherwise the expression value is converted to an unsigned int. Example, char c = ‘A’; printf(“%c\n”, c); Type of the expression c in printf above, is int, not char. Automatic Conversion Examples</p><p>Casts (Type Converters)</p><p>(double) i Expression type is double (i type not changed) (long) (‘A’ + 1.0) Expression type is long x = (float) ((int) y + 1) Expression types are int, float (double) (x = 77) Expression type is double (x type not changed) </p><p>Cast Operator has higher precedence than arithmetic operators, i.e., (float) i + 3 .eqv. ((float) i) + 3</p><p>6.13 System Considerations</p><p>. IEEE Standard for Floating Point Arithmetic . Cray Integers . Turbo C – “A long double is stored in ten bytes.” => Doubtful!!! </p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    7 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us