1 / 16

3-3 Side Effects

Learn about side effects in C programming, from expression evaluation to type conversion. Understand implicit and explicit type conversion, with examples. Explore statements in C programming to perform actions in a program.

jcoombs
Download Presentation

3-3 Side Effects

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression on the right of the assignment operator and then places the value in the left variable. Changing the value of the left variable is a side effect. Computer Science: A Structured Programming Approach Using C

  2. PROGRAM 3-6 Evaluating Expressions Computer Science: A Structured Programming Approach Using C

  3. PROGRAM 3-6 Evaluating Expressions Computer Science: A Structured Programming Approach Using C

  4. PROGRAM 3-6 Evaluating Expressions Computer Science: A Structured Programming Approach Using C

  5. Warning Computer Science: A Structured Programming Approach Using C

  6. 3-5 Type Conversion Up to this point, we have assumed that all of our expressions involved data of the same type. But, what happens when we write an expression that involves two different data types, such as multiplying an integer and a floating-point number? To perform these evaluations, one of the types must be converted. Topics discussed in this section: Implicit Type Conversion Explicit Type Conversion (Cast) Computer Science: A Structured Programming Approach Using C

  7. FIGURE 3-10 Conversion Rank Computer Science: A Structured Programming Approach Using C

  8. PROGRAM 3-7 Implicit Type Conversion Computer Science: A Structured Programming Approach Using C

  9. PROGRAM 3-7 Implicit Type Conversion Computer Science: A Structured Programming Approach Using C

  10. PROGRAM 3-7 Implicit Type Conversion Computer Science: A Structured Programming Approach Using C

  11. Implicit Conversion of Ints and Floats int i = 3; float f = 2.5; i = f; // i will equal 2 after this f = 3/i; // f will equal 1.0 after this f = i + 0.6; // f will equal 2.6 after this i = 2.0 * 2.4; // i will equal 4 after this Computer Science: A Structured Programming Approach Using C

  12. PROGRAM 3-8 Explicit Casts Computer Science: A Structured Programming Approach Using C

  13. PROGRAM 3-8 Explicit Casts Computer Science: A Structured Programming Approach Using C

  14. PROGRAM 3-8 Explicit Casts Computer Science: A Structured Programming Approach Using C

  15. 3-6 Statements A statement causes an action to be performed by the program. It translates directly into one or more executable computer instructions. You may have noticed that we have used a semicolon at the end of the statements in our programs. Most statements need a semicolon at the end; some do not. Computer Science: A Structured Programming Approach Using C

  16. FIGURE 3-12 Compound Statement Computer Science: A Structured Programming Approach Using C

More Related