L7 - 7. BASIC TYPES Systems of numeration Numeric Types Cs...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
7. BASIC TYPES
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Systems of numeration
Background image of page 2
Numeric Types C’s basic types include integer types and floating types. Integer types can be either signed or unsigned. A value of a signed type can be either negative, zero, or positive. A value of an unsigned type must be zero or positive.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Integer Types C provides six integer types: C99 also supports the long long int type, whose values typically range from –2 63 to 2 63 – 1, and unsigned long long int, whose values typically range from 0 to 2 64 – 1.
Background image of page 4
Integer Types Integer types can be abbreviated by omitting the word int: long i; /* same as long int i; */ In general, avoid using unsigned types. <limits.h> INT_MIN INT_MAX
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Integer Constants Integer constants may be written in decimal (base 10), octal (base 8), or hexadecimal (base 16). Decimal integer constants contain digits, but must not begin with a zero: 15 255 32767 Octal integer constants contain only digits between 0 and 7, and must begin with a zero: 017 0377 077777
Background image of page 6
Integer Constants Hexadecimal integer constants contain digits between 0 and 9 and letters between A and F (or a and f), and always begin with 0x: 0xf 0xff 0x7fff The letters in a hexadecimal constant may be either upper or lower case. Force type 15L 0377L 0x7fffL 15U 0377U 0x7fffU 0xffffffffUL
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Integer Overflow Signed Unsigned
Background image of page 8
Reading and Writing Integers When reading or writing an unsigned integer, use the letter u (decimal), o (octal), or x (hex) in the conversion specification: unsigned int u; printf("%u", u); /* writes u in base 10 */ printf("%o", u); /* writes u in base 8 */ printf("%x", u); /* writes u in base 16 */ When reading or writing a short integer, put the letter h in front of d, o, x, or u: short int s; printf("%hd", s);
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Reading and Writing Integers When reading or writing a long integer, put the letter l in front of d, o, x, or u: long int l; printf("%ld", l);
Background image of page 10
Floating Types C supports three floating types: (Ranges shown are typical.)
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Floating Constants Floating constants can be written in either fixed-point notation or scientific notation. Examples of fixed-point notation: 57.0 57. Examples of scientific notation:
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/08/2011 for the course CGS 3460 taught by Professor Staff during the Summer '08 term at University of Florida.

Page1 / 33

L7 - 7. BASIC TYPES Systems of numeration Numeric Types Cs...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online