Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.

Slides:



Advertisements
Similar presentations
1 Chapter 3:Operators and Expressions| SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2006 | Last Updated: July 2006 Slide 1 Operators and Expressions.
Advertisements

IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
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.
Chapter 2: Java Fundamentals Operators. Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 2 Content Group of Operators Arithmetic Operators Assignment.
1 Data types, operations, and expressions Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Expressions and Operators Program Style.
Operator. Assignation (=). The assignation operator serves to assign a value to a variable. a = 5; It is necessary to emphasize that the assignation operation.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
Fall 2006AE6382 Design Computing1 Relational and Logical Operators Use relational operators to test two values Work with values of true and false Compare.
Chapter 4: Basic C Operators
Section 1.1 Numbers and Their Properties.
Chapter 4: Operators Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills /1436.
The Basic of Algebra BY Nathaniel Jefferson. The Number Line  |  0 Always start at zero.
Exercises A-Declare a variable of double type with initial value=0.0; B- Declare a constant of String type with initial value=“Good” C- Declare a variable.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
2440: 211 Interactive Web Programming Expressions & Operators.
LESSON 6 – Arithmetic Operators
Variables and Arithmetic. From last class More drawing functions: strokeWeight(n); // higher the n value broader the stroke fill(k) ; // single parameter.
Basic Operators. What is an operator? using expression is equal to 9. Here, 4 and 5 are called operands and + is the operator Python language supports.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
C Programming Lecture 6 : Operators Lecture notes : courtesy of Ohio Supercomputing Center, and Prof. Woo and Prof. Chang.
CPS120: Introduction to Computer Science Operations Lecture 9.
C Operators. CONTENTS C OPERATORS TYPES OF OPERATOR UNARY BINARY TERNARY ARITHMATIC RELATIONAL LOGICAL.
Section 2.1 Solving Equations Using Properties of Equality.
Multiplication of Real Numbers Section 2.5. Multiplying Rules 1) If the numbers have the same signs then the answer is positive. (-7) (-4) = 28 2) If.
1.3 Solving Linear Equations
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
< < < > < > <
Operators & Expressions
Sullivan Algebra and Trigonometry: Section 1.1 Objectives of this Section Solve an Equation in One Variable Solve a Linear Equation Solve Equations That.
Addition Multiplication Subtraction Division. 1.If the signs are the same, add the numbers and keep the same sign = = If the.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
STRUCTURED PROGRAMMING C++ Operators. Content 2  C++ operators  Assignment operators  Arithmetic operators  Increment and decrement operators  Decision.
Expression and Operator. Expressions and Operators u Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); u Two types: –Function calls –The expressions formed.
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
1 2. Program Construction in Java. 01 Java basics.
CHAPTER 2 PART #4 OPERATOR 1 st semester King Saud University College of Applied studies and Community Service Csc
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Section 6.2 Solving Linear Equations Math in Our World.
Rational Expressions relational operators logical operators order of precedence.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
Arithmetic Instructions. Integer and Float Conversions.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Rational Expressions. relational operators. logical operators
INSPIRING CREATIVE AND INNOVATIVE MINDS
Relational Operations
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
Assignment and Arithmetic expressions
Solving 1-Step Integer Equations
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
Solving Equations with the Variable on Both Sides
C Operators, Operands, Expressions & Statements
Expressions.
Chapter 3 Operators and Expressions
Relational Operators.
Chapter 4: Expression and Operator
Chap 7. Advanced Control Statements in Java
Assignment Operators Topics Increment and Decrement Operators
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
OPERATORS in C Programming
OPERATORS in C Programming
Chapter 12 Variables and Operators
Presentation transcript:

Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =. A unary operator takes one value and gives one result: OP x where OP can be +, -, &, !, ++, etc.

Arithmetic Operators + Add - Subtract * Multiply / Divide % Modulus Examples:   -2 3 * 2  6 4 / 2  2 10 % 3  1

Arithmetic Operators, Examples char c, d; int i, j; float w, x; double y, z; c = 8; d = 'R'; i = 76; w = 7.9; y = e8; j = i * i; (j gets 76  76=5776) j = i * c; (j gets 76  8=608) j = i / c; (j gets 9, fractional part dropped) j = i * d; (j gets 76  82=6232) x = i / w; (x gets 76/7.9= ) j = i / w; (j gets 9, fractional part dropped) z = w * y; (z gets 7.9   10 8 = ) This is Example 3.3.1, page 84.

Operator Precedence and Associativity How is the expression computed if there are multiple binary operators involved? For example: x OP1 y OP2 z Is it (x OP1 y ) OP2 z or x OP1 (y OP2 z)? Answer: §Operators with high precedence are acted first. §Operators of the same precedence follow the association rule (from left to right or right to left).

Precedence Operators *, /, and % have higher precedence than +, -. Thus * 4 is 5 + (3 * 4) = =17 8 % is (8 % 3) + 5 = = 7

Association Operators *, /, and % have the save precedence; operator + and - have the same precedence. They all associates from left to right. Thus is (5 - 3) + 4 = = 6 8 % 3 * 5 is (8 % 3) * 5 = 2 * 5 = 10

Assignment Operators The operators used in the form x op= y (no space between op and =) is equivalent to x = x op ( y ) where op is +, -, *, /, %, >>, <<, &, ^ or |. Examples: x += 3  x = x + 3 y *= x+z  y = y*(x+z)

Relational and Logical Operators Relational == equal != not equal > greater than >= greater than or equal < less than <= less than or equal Logical && and || or ! not

Relational Operators int x, y, z; x = 1; y = 4; z = 14; Expression value x < y + z1 (true) y == 2 * x + 30 (false) z <= x + y0 (false) z > x1 (true) x != y1 (true) The values of relational and logical expressions are 0 (for false) and 1 (for true). This is Example 3.4.2, page 89.

Logical Operators Zero (0) denotes false; any nonzero values (e.g. 1, 7, or -2) denotes true.

Logical Operators int x, y, z; x = 1; y = 4; z = 14; Expression value x <= 1 && y == 3 0 (false) x <= 1 || y == 3 1 (true) !(x > 1) 1 (true) !x > 1 0 (false) !(x<=1 || y==3) 0 (false) x >= 1 && y == 3 || z < 14 0 (false) This is Example 3.4.4, page 91

Assignment Operators The equal sign = is also considered an operator and the construct x = y is also an expression. Every expression has a value. The value of x = y is the value assigned to the variable x. A semicolon turns an expression into a statement. E.g., x = y;

Assignment Operators Associate from Right to Left The expression x = y = z means x = (y = z) If z is 10, the value 10 will be assigned to y and in turn assigned to x.

Reading/Home Working Read Chapter 3, page 83 to 94. Work on Problems –Section 3.3, page 88, exercise 1, 3, 5. –Section 3.4, page 94, exercise 1. Check your answers in the back of the textbook. Do not hand in.