cs246-s11-001-may19

cs246-s11-001-may19 - CS 246 (Spring 2011) Section 1...

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

View Full Document Right Arrow Icon
CS 246 (Spring 2011) – Section 1 Thursday 19 May Structured Programming
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 19 May 2 Today's Agenda 2.4.1 / 2.4.2 Conversion and Coercion Some wording changes in the course notes 2.5 Control Structures Mostly review Will see some new examples 2.6 Structured Programming
Background image of page 2
CS 246 (Spring 2011) - Section 001 - Thursday 19 May 3 2.4.1 Conversion Conversion : Transforming a value having type X to a value having type Y Two types: widening and narrowing Widening/promotion : no loss of information bool → char → short int → int → double Narrowing : possible information loss double → int → short int → char → bool 77777.7. ..7 → 77777 → 12241 → 209 → 1 (true)
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 19 May 4 Conversion (ctd.) Widening or narrowing can be implicit Implicit narrowing can be problematic int i; double r; i = r = 3.5; r = i = 3.5; Narrowing should be done explicitly ( casting ) int i; double x = 7.2; double y = 3.5; i = (int) x; i = (int) x / (int) y; i = static_cast<int>(x / y);
Background image of page 4
CS 246 (Spring 2011) - Section 001 - Thursday 19 May 5 2.4.2 Coercion Coercion : Transforming a value having type X to a value having type Y, where the result is not meaningful in the new representation char 'a' → true long int 77777 → short int 12241 char ch = 'z' - 'a'; Two interpretations of char Coercion with pointers To be covered later
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 19 May 6 2.5 Control Structures This section is mostly review from CS 136 Two examples illustrating pitfalls Exiting a loop The switch statement Select alternatives for an integral value Example Additional syntax is introduced in the next section on structured programming e.g. goto statements
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 21

cs246-s11-001-may19 - CS 246 (Spring 2011) Section 1...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online