All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.

Slides:



Advertisements
Similar presentations
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Advertisements

LECTURE 3: BASIC C OPERATORS. Objectives  In this chapter, you will learn about:  Arithmetic operators Unary operators Binary operators  Assignment.
Department of Computer Science. Definition “An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
1 Operators And Expressions. 2 Operators Arithmetic Operators Relational and Logical Operators Special Operators.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
Operators. Perl has MANY operators. –Covered in Chapter 3 of Prog.Perl Most operators have numeric and string version –remember Perl will convert variable.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
JavaScript, Third Edition
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
1 MATERI PENDUKUNG OPERATOR Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
C Operators, Operands, Expressions & Statements Hands-on, crash course with code examples 1/46 ©
Chapter 4: Basic C Operators
Chapter 4: Operators Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills /1436.
Ryan Chu. Arithmetic Expressions Arithmetic expressions consist of operators, operands, parentheses, and function calls. The purpose is to specify an.
Chapter 6. Dataflow Modeling. Continuous Assignments The left hand side always be a scalar or vector net or a concatenation of scalar and vector nets.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.
LESSON 6 – Arithmetic Operators
C Operators. CONTENTS CONDITIONAL OPERATOR SIMPLE ASSIGNMENT OPERATOR COMPOUND ASSIGNMENT OPERATOR BITWISE OPERATOR OPERATOR PRECEDENCE.
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.
C Programming Lecture 6 : Operators Lecture notes : courtesy of Ohio Supercomputing Center, and Prof. Woo and Prof. Chang.
C Operators. CONTENTS C OPERATORS TYPES OF OPERATOR UNARY BINARY TERNARY ARITHMATIC RELATIONAL LOGICAL.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
15-Nov-15 All the Operators. operators.ppt 2 Precedence An operator with higher precedence is done earlier (precedes) one with lower precedence A higher.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
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.
C# Operator Overloading and Type Conversions C#.NET Software Development Version 1.0.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Java Operator Precedence Operator Meaning Assoc. ===========================================================.
Expressions and Operators in C. Expressions and Operators Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); Two types: – Function calls – The expressions.
Operators & Expressions
CSEB 114: PRINCIPLE OF PROGRAMMING Chapter 4: Basic C Operators.
OperatorstMyn1 Operators An operator is something that you feed with one or more values (or expressions, in programming jargon) which yields another value.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
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.
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.
Programming Principles Operators and Expressions.
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Camel –perldoc perlop Many operators have numeric and string version –remember Perl will.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2012 CMPE-013/L Operators Gabriel Hugh Elkaim Spring 2012.
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.
Operator Kinds of Operator Precedence of Operator Type Casting.
DEPARTMENT OF COMPUTER SCIENCE C Operators, Operands, Expressions & Statements 1/46 BCA I ST YR (SEMESTER I) PRESENTED BY SHAZIA SHAFI Dated:
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
CSE 220 – C Programming Expressions.
Chapter 12 Variables and Operators
Operators And Expressions
Operators and Expressions
Side Effect Operators Changing the value of variables
University of Central Florida COP 3330 Object Oriented Programming
University of Central Florida COP 3330 Object Oriented Programming
Arithmetic Operator Operation Example + addition x + y
Chapter 12 Variables and Operators
Lecture 3 Expressions Richard Gesick.
All the Operators 22-Nov-18.
More about Numerical Computation
All the Operators 4-Dec-18.
Chapter-3 Operators.
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Chapter 4: Expression and Operator
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
Presentation transcript:

All the Operators

Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated with a lower number; zero is the highest precedence Most of the time, operators with equal precedence are done left to right –Examples: * 5 gives gives 3 Exceptions: unary operators, casts, assignment operators, the ternary operator: all done right to left

Postfix operators ( parameters ) Parameter lists [ ] Brackets indicate indexing into an array. Accesses methods and variables expr ++, expr -- Postincrement, postdecrement

Unary prefix operators ++ expr Preincrement -- expr Predecrement + - Unary plus and unary minus ! Logical negation (not) ~ Bitwise complement (invert every bit)

Object creation and casting new Create a new instance of a class ( type ) Cast (convert) to the given type Slides are in order of decreasing precedence –Higher precedence means “more tightly bound” –The lowest precedence operator is the “main” operator in an expression

Multiplicative operators * Multiply / Divide % Modulus These all have the same precedence

Additive operators + Add - Subtract

Shift operators << Left shift, end off –For small integers, this is equivalent to multiplying by a power of two –Example: 100 << 3 gives 800 >> Right shift with sign extension –For small integers, this is equivalent to an integer divide by a power of two –Example: 100 >> 2 gives 25 >>> Right shift with zero fill –Does not make sense for numbers

Relational operators < Less than <= Less than or equal to > Greater than >= Greater than or equal to These all have the same precedence, and it is higher than equality/inequality tests

Equality and inequality == Test if equal –For primitive types, tests if the values are equal –For objects, tests if both sides refer to the same object != Test if not equal –For primitive types, tests if the values are unequal –For objects, tests if the sides refer to different objects

AND & AND –For integral types, ANDs each corresponding pair of bits –For booleans, performs the logical AND operation Boolean & is like &&, but both operands are evaluated, even if it is possible to decide the result from the left operand alone

Exclusive OR ^ XOR –For integral types, XORs each corresponding pair of bits –For booleans, performs the logical XOR operation a ^ b is true if either a is true or b is true, but not both There is no ^^ operation

OR | OR –For integral types, ORs each corresponding pair of bits –For booleans, performs the logical OR operation Boolean | is like ||, but both operands are evaluated, even if it is possible to decide the result from the left operand alone

The ternary operator boolean-expr ? expression-1 : expression-2 This is like if-then-else for values rather than for statements If the boolean-expr evaluates to true, the result is expression-1, else it’s expression-2 Example: max = a > b ? a : b ; sets the variable max to the larger of a and b expression-1 and expression-2 need not be the same type, but either result must be useable The ternary operator is right associative! –Use parentheses if more than one ternary operator

The assignment operators I The assignment operators have the lowest precedence –Assignment is an operation –Assignment is right associative a = b = c = 7.5 * w; assigns 7.5*w to c, then assigns c to b, then assigns b to a – if all these assignments are legal Example: – if ((line = reader.newLine()) == null) {... }

The assignment operators II There are a lot of assignment operations besides = variable += expression means the same as variable = variable + expression variable -= expression means the same as variable = variable - expression variable *= expression means the same as variable = variable * expression variable /= expression means the same as variable = variable / expression

The assignment operators III variable %= expression means the same as variable = variable % expression variable <<= expression means the same as variable = variable << expression variable >>= expression means the same as variable = variable >> expression variable >>>= expression means the same as variable = variable >>> expression

The assignment operators IV variable &= expression means the same as variable = variable & expression variable |= expression means the same as variable = variable | expression variable ^= expression means the same as variable = variable ^ expression

What you need to know You should understand what each operator does Parameter lists, array indexing, and the dot operator are done first In arithmetic, the unary operators + and – are done first, then multiplication and division, then addition and subtraction All assignment operators are done last For anything else, it’s a good idea to use parentheses anyway (even if you remember the order of precedence, other people won’t)

The End