Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.
-
Upload
geoffrey-fisher -
Category
Documents
-
view
219 -
download
0
description
Transcript of Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.
![Page 1: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/1.jpg)
Basic Types
CGS 3460, Lecture 19Feb 22, 2006Hen-I Yang
![Page 2: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/2.jpg)
Previously… goto, null statement Road map to more advanced topics.
![Page 3: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/3.jpg)
Agenda
Homework 3 Types int float
![Page 4: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/4.jpg)
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
![Page 5: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/5.jpg)
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.
![Page 6: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/6.jpg)
Homework 3: Problem 1 Realty Consultant Problem 3.1 Pick best house out of five
![Page 7: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/7.jpg)
Homework 3 (II): Problem 2 Draw a Map Find
OptimalHouseLocation
![Page 8: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/8.jpg)
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”);
}
![Page 9: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/9.jpg)
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.
![Page 10: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/10.jpg)
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)
![Page 11: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/11.jpg)
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”
![Page 12: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/12.jpg)
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)
![Page 13: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/13.jpg)
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
![Page 14: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/14.jpg)
Summary
Quiz 2 Homework 3 Type int
![Page 15: Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.](https://reader035.fdocuments.net/reader035/viewer/2022062412/5a4d1afc7f8b9ab0599843d5/html5/thumbnails/15.jpg)
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)