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.

Slides:



Advertisements
Similar presentations
Type Conversion. C provides two methods of changing the type of an expression: Type conversion (done implicitly) Cast expressions (done explicitly) Examples.
Advertisements

ISBN Chapter 7 Expressions and Assignment Statements.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 3 Expressions.
1 9/13/06CS150 Introduction to Computer Science 1 Type Casting.
Constants and Variables  Memory cells used in program  Called constants and variables  Identifiers for constants and variables should be declared before.
Review Question What kind error is it when I try to multiply a number in a program by 1000 and store in a variable, but the variable is too small for the.
1 9/17/07CS150 Introduction to Computer Science 1 Type Casting.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Expressions and Operators Program Style.
CS150 Introduction to Computer Science 1
Expressions An expression is a sequence of operands and operators that reduces to a single value expression operator operand An operator is a language-specific.
ISBN Chapter 7 Expressions and Assignment Statements.
1  Ex: Declare a variable to store user’s age: int age; Prompt the user to enter his/her age: printf (“ How old are you? “); Read / scan the entered value.
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
First Order Linear Equations Integrating Factors.
1-1 University of Hail College of Computer Science and Engineering Department of computer Science and Software Engineering Course: ICS313: Fundamentals.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
C H A P T E R S E V E N Expressions and Assignment Statements.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Section 2.5 – Implicit Differentiation. Explicit Equations The functions that we have differentiated and handled so far can be described by expressing.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand.
1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand the rules of precedence and associativity in evaluating expressions.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the structure, union, and enumerated types ❏ To use the type definition.
Chapter 7 Expressions and Assignment Statements. Outline Introduction Arithmetic Expressions Overloaded Operators Type Conversions Assignment Statements.
LOOP & Type Conversion. do – while Loop In the while loop, the test expression is evaluated at the beginning of the loop. If the test condition is false.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Java Statements –Java Expressions –Postfix Expressions –Prefix Expressions –Evaluating.
LESSON 5 – Assignment Statements JAVA PROGRAMMING.
Computer Science: A Structured Programming Approach Using C1 5-5 Incremental Development Part II In Chapter 4, we introduced the concept of incremental.
C-1 9/30/99 CSE / ENGR 142 Programming I Arithmetic Expressions © 1999 UW CSE.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Chapter 7 Expressions and Assignment Statements. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 7 Topics Introduction Arithmetic Expressions.
Arithmetic Instructions. Integer and Float Conversions.
1 Section 3.2b Arithmetic Operators Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Arithmetic Expressions
Expressions and Assignment Statements
Expressions and Assignment Statements
Chapter 12 Enumerated, Structure, and Union Types Objectives
© 2016, Mike Murach & Associates, Inc.
Expressions and Assignment Statements
Chapter 2 Elementary Programming
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Arithmetic operations & assignment statement
Expressions and Assignment Statements
Topics discussed in this section:
Arithmetic Operator Operation Example + addition x + y
Expressions and Assignment Statements
Structure of a C Program
Lecture 3 Expressions Richard Gesick.
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.
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Numerical Data Types.
Expressions and Assignment Statements
A First Book of ANSI C Fourth Edition
College of Computer Science and Engineering
Section 1-6: Multiplying Integers
Topics discussed in this section:
Topics discussed in this section:
Expression and Asignment Statements
Doing Arithmetic Today’s lecture is in chapter 2 Assignment statement:
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Data Types and Expressions
Chapter 7 Expressions and Assignment Statements.
Data Types and Expressions
PRESENTED BY ADNAN M. UZAIR NOMAN
Expressions and Assignment Statements
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

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

Topics discussed in this section: 3-4 Evaluating Expressions Now that we have introduced the concepts of precedence, associativity, and side effects, let’s work through some examples. Topics discussed in this section: Expressions without Side Effects Expressions with Side Effects Computer Science: A Structured Programming Approach Using C

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

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

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

Warning Computer Science: A Structured Programming Approach Using C

Topics discussed in this section: 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

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

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

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

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

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

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

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

Topics discussed in this section: 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. Topics discussed in this section: Statement Type The Role of the Semicolon Statements and Defined Constants Computer Science: A Structured Programming Approach Using C

FIGURE 3-11 Types of Statements Computer Science: A Structured Programming Approach Using C

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

The compound statement does not need a semicolon. Note The compound statement does not need a semicolon. Computer Science: A Structured Programming Approach Using C