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

C++ Statements represent the lowest-level building blocks of a program and it may be like:. A simple statement is a computation terminated by a semicolon.
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.
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.
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.
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 =
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.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
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.
CP104 Introduction to Programming Overview of C Lecture 4__ 1 Assignment Statements An assignment statement is to store a value in a variable variable.
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.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
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.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
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.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
Arithmetic Instructions. Integer and Float Conversions.
1 Section 3.2b Arithmetic Operators Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Expressions and Assignment Statements
Expressions and Assignment Statements
7.2 Arithmetic Expressions
Chapter 7: Expressions and Assignment Statements
Expressions and Assignment Statements
Chapter 7: Expressions and Assignment Statements
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
Arithmetic Expressions
Conversions of the type of the value of an expression
Structure of a C Program
Explicit and Implicit Type Changes
OPERATORS (2) CSC 111.
Increment and Decrement
Lecture 3 Expressions Richard Gesick.
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
Arithmetic Expressions & Data Conversions
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.
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.
CS150 Introduction to Computer Science 1
Data Types and Expressions
Chapter 7 Expressions and Assignment Statements.
Data Types and Expressions
Relational Operators.
Casting Converting types.
PRESENTED BY ADNAN M. UZAIR NOMAN
Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a language-specific syntactical token.
Data Types and Expressions
Arithmetic Expressions & Data Conversions
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

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

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

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

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

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