9. Data Types

# 9. Data Types - ENGR 101 Data Types ENGR 101, Lecture 9: 11...

This preview shows pages 1–6. Sign up to view the full content.

ENGR 101 1 Data Types ENGR 101, Lecture 9: 11 Oct 10 Today's Question How high can you count on the fingers of one hand?

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

View Full Document
ENGR 101 2 Announcements Project 4 due Wed 9pm How is your progress on Project 4? A. Have not started yet B. Started, not very far yet C. Have single game mode (option 0) working D. Just fixing last few things E. Completed Two Key Elements of Programming Flow of Control Sequence Selection Iteration Data Representation How do we structure the data that we are acting on?
ENGR 101 3 Data Types Definition a set of possible values plus , a set of legal operations on those values for example ( int ): Integers within a given range Operations: addition ( + ), subtraction ( - ), etc. Mixed-Type Expressions Even when binary operators are defined for operands of same type, can often apply them to different types. For example, arithmetic operators: 53 + 26.2 53 / 26.2 26.2 - true To evaluate, more restricted operand is promoted to type of the other bool ˠ int ˠ double

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

View Full Document
ENGR 101 4 Type Coercion Coercion : The implicit (automatic) conversion of a value from one data type to another Coercion may apply when: Evaluating a mixed-type expression Assigning a value double myDub = 3; int myInt = 24.9; double avg = 39/5; Passing a value to a routine Returning a value from a function promoted to 3.0 demoted to 24 promoted to ?? Type Casting Cast : The explicit conversion of a value from one data type to another Syntax of cast operation: T ( expr ) Evaluates expr, converts to type T int(24.9) int(x+0.5) double(39)/5 Explicit cast often recommended for clarity, even when coercion would apply 24 (just takes whole part) rounds to nearest int (if x positive) 7.8
ENGR 101 5 Data Representation All data inside the computer is represented by bits. Bits can have only two values 0 or 1.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/25/2011 for the course ENGR 101 taught by Professor Ringenberg during the Fall '07 term at University of Michigan.

### Page1 / 17

9. Data Types - ENGR 101 Data Types ENGR 101, Lecture 9: 11...

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

View Full Document
Ask a homework question - tutors are online