Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang.

Similar presentations


Presentation on theme: "Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang."— Presentation transcript:

1 Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang

2 Previously… goto, null statement Road map to more advanced topics.

3 Agenda Homework 3 Types int float

4 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

5 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.

6 Homework 3: Problem 1 Realty Consultant Problem 3.1 Pick best house out of five

7 Homework 3 (II): Problem 2 Draw a Map Find Optimal House Location

8 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”); }

9 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.

10 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)

11 Types (II) Three basic types  int  float  char 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”

12 int int, short, long signed, 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)

13 Int (II) The values are machine dependent However, the relative size of short, int and long always remain Range short <= Range int <= Range long Usually, if an integer is expected to exceed 32767, we use 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

14 Summary Quiz 2 Homework 3 Type int

15 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)


Download ppt "Basic Types CGS 3460, Lecture 19 Feb 22, 2006 Hen-I Yang."

Similar presentations


Ads by Google