basic types cgs 3460, lecture 19 feb 22, 2006 hen-i yang
DESCRIPTION
Agenda Homework 3 Types int floatTRANSCRIPT
Basic Types
CGS 3460, Lecture 19Feb 22, 2006Hen-I Yang
Previously… goto, null statement Road map to more advanced topics.
Agenda
Homework 3 Types int float
A Glimpse of Quiz 2 What is in Quiz 2?
Everything related to Homework2 Everything in the textbook up to Section 5-2 Everything listed on the “topics” page up to Feb 10
About Quiz 2 Bring Gator 1 ID 20 minutes starting 9:35 am sharp No electronic device of any sort is allowed To have homework 2 counted toward your grade, you
have to take quiz 2. Lecture will continue after the completion of the quiz
Homework 3: Prologue
Professor Dumbledore has just accepted to join UF as a visiting professor for one year. As the house/apartment rental season fast approaching, he is trying to find the best housing available for his family in the Gainesville area as soon as possible.
Homework 3: Problem 1 Realty Consultant Problem 3.1 Pick best house out of five
Homework 3 (II): Problem 2 Draw a Map Find
OptimalHouseLocation
Homework 3 (III) Hints How do we calculate absolute values?
A function called abs() [NOT ALLOWED] if (x > y) z = x – y; else z = y – x; z = (x > y) ? x – y : y – x;
How do we work through two dimension grids? Nested loops for (x = 1; x <=25; x++) {
for (y = 1; y <= 25; y++) { // You may need to check for special locations printf(“.”);
}printf(“\n”);
}
STAGE 3
We are moving on the more advance materials now.
Types: What are they, why are they important
Arrays: Tired of declaring 10 variables for 10 entries of the same thing?
Functions: How do we pack code segments into something more meaningful?
Pointers: Let the fun begins.
Types
Every data of variable is stored in the form of binary.
Compiler/CPU handles the variables based on what the programmer makes of it
Compiler does “type conversion” automatically based on certain rules
Programmers can explicitly make data another type that it was not meant to be (casting)
Types (II)
Three basic types int floatchar
The range and precision of value, or even presentation of the value of a variable can hold is machine dependent.
C language specification is flexible in these “details”
intint, short, longsigned, unsigned Integers are stored as binary, sometimes with bit sign You can specify different “sizes” of int You can also specify signed and unsigned flavor of int beware of the max/min of int, otherwise it might overflow
The max/min depends on whether the machine is 16 or 32 bits, also depends on signed/unsigned
By default, int are signed (unsigned has be to specifically declared)
If a 16-bit integer, with maximum allowed value 32767 is barely enough, then use long int
Long/unsigned/int can be permuted (order does not matter, int can be omitted)
Int (II) The values are machine dependent However, the relative size of short, int and long always r
emain Rangeshort <= Rangeint <= Rangelong Usually, if an integer is expected to exceed 32767, we us
e long for portability, but long may operate more slowly because there are more bits to operate on
Revisit: Decimal, Octal 017 0377, Hexadecimal 0xf 0xff 0xFF 0XFF
When specified as a constant expression 15L, 0377L, 0x7fffL (long) 15U, 0377U, 0x7fffU (unsigned)
More conversion specifications %u, %o, %x, %hd (short), %ld (long) %d only work for int
Summary
Quiz 2 Homework 3 Type int
Before you go
Read Chapter 7. Exercise: 7.3, 7.4 Quiz 2 on Feb 24, Friday at 9:35 am,
remember to bring Gator 1 ID card Homework 2 late submission ends
tomorrow night (Feb 23, Thursday at 11:59 pm)