{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

chapter07 - COP 3275 Chapter 07 Jonathan C.L Liu Ph.D CISE...

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

View Full Document Right Arrow Icon
COP 3275: Chapter 07 Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA
Background image of page 1

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

View Full Document Right Arrow Icon
Basic Types C’s basic (built-in) types: Integer types, including long integers, short integers, and unsigned integers Floating types ( float , double , and long double ) char _Bool (C99) 2
Background image of page 2
Integer Types C supports two fundamentally different kinds of numeric types: integer types and floating types. Values of an integer type are whole numbers. Values of a floating type can have a fractional part as well. The integer types, in turn, are divided into two categories: signed and unsigned. 3
Background image of page 3

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

View Full Document Right Arrow Icon
Signed and Unsigned Integers The leftmost bit of a signed integer (known as the sign bit ) is 0 if the number is positive or zero, 1 if it’s negative. The largest 16-bit integer has the binary representation 0111111111111111, which has the value 32,767 (2 15 – 1). The largest 32-bit integer is 01111111111111111111111111111111 which has the value 2,147,483,647 (2 31 – 1). An integer with no sign bit (the leftmost bit is considered part of the number’s magnitude) is said to be unsigned. The largest 16-bit unsigned integer is 65,535 (2 16 – 1). The largest 32-bit unsigned integer is 4,294,967,295 (2 32 – 1). 4
Background image of page 4
Signed and Unsigned Integers By default, integer variables are signed in C—the leftmost bit is reserved for the sign. To tell the compiler that a variable has no sign bit, declare it to be unsigned . Unsigned numbers are primarily useful for systems programming and low-level, machine- dependent applications. 5
Background image of page 5

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

View Full Document Right Arrow Icon
Integer Types The int type is usually 32 bits, but may be 16 bits on older CPUs. Long integers may have more bits than ordinary integers; short integers may have fewer bits. The specifiers long and short , as well as signed and unsigned , can be combined with int to form integer types. Only six combinations produce different types: short int unsigned short int int unsigned int long int unsigned long int The order of the specifiers doesn’t matter. Also, the word int can be dropped ( long int can be abbreviated to just long ). 6
Background image of page 6
Integer Types The range of values represented by each of the six integer types varies from one machine to another. However, the C standard requires that short int , int , and long int must each cover a certain minimum range of values. Also, int must not be shorter than short int , and long int must not be shorter than int . 7
Background image of page 7

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

View Full Document Right Arrow Icon
Integer Types Typical ranges of values for the integer types on a 16-bit machine: TypeSmallest ValueLargest Value short int –32,768 32,767 unsigned short int 065,535 int –32,768 32,767 unsigned int 0 65,535 long int –2,147,483,6482,147,483,647 unsigned long int 04,294,967,295 8
Background image of page 8
Integer Types Typical ranges on a 32-bit machine: Type Smallest ValueLargest Value short int –32,768 32,767 unsigned short int 0 65,535 int –2,147,483,6482,147,483,647 unsigned int 0 4,294,967,295 long int –2,147,483,6482,147,483,647 unsigned long int 0 4,294,967,295 9
Background image of page 9

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

View Full Document Right Arrow Icon
Integer Types Typical ranges on a 64-bit machine: TypeSmallest ValueLargest Value short int –32,768 32,767 unsigned short int 0 65,535 int –2,147,483,6482,147,483,647 unsigned int 0 4,294,967,295 long int –2 63 2 63 –1 unsigned long int 02 64 –1 The <limits.h> header defines macros that represent the smallest and largest values of each integer type.
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}