Chapter 4: Expression and Operator

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.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
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 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
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 CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
Chapter 4: Basic C Operators
Chapter 4: Operators Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills /1436.
7-1 Chapter 7: Expressions and Assignment Statements Arithmetic Expressions –the fundamental means of specifying computations in a programming language.
Ryan Chu. Arithmetic Expressions Arithmetic expressions consist of operators, operands, parentheses, and function calls. The purpose is to specify an.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
LESSON 6 – Arithmetic Operators
CHAPTER 2 PART #4 OPERATOR 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101 By: Asma Alosaimi Edited.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand.
C Programming Lecture 6 : Operators Lecture notes : courtesy of Ohio Supercomputing Center, and Prof. Woo and Prof. Chang.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
CP104 Introduction to Programming Overview of C Lecture 4__ 1 Assignment Statements An assignment statement is to store a value in a variable variable.
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.
Expressions and Assignment Statements
ISBN Chapter 7 Expressions and Assignment Statements.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
4. EXPRESSIONS. Display the value of pi, to 5 decimal places, right justified, in 9 columns Read in someone’s height in feet and inches using.
Operators & Expressions
STRUCTURED PROGRAMMING C++ Operators. Content 2  C++ operators  Assignment operators  Arithmetic operators  Increment and decrement operators  Decision.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
ISBN Chapter 7 Expressions and Assignments Statements.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
Expressions and Assignment Statements
Operators & Expressions
Expressions and Assignment Statements
CSE 220 – C Programming Expressions.
Chapter 12 Variables and Operators
Operators And Expressions
Operators and Expressions
Expressions and Assignment Statements
Side Effect Operators Changing the value of variables
University of Central Florida COP 3330 Object Oriented Programming
CS2403 Programming Languages Expressions and Assignment Statements
University of Central Florida COP 3330 Object Oriented Programming
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.
Expressions and Assignment Statements
Computer Programming: C language
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
Expressions Chapter 4 Copyright © 2008 W. W. Norton & Company.
Expressions and Assignment Statements
C Operators, Operands, Expressions & Statements
Chapter-3 Operators.
Expressions and Assignment Statements
Associativity and Prescedence
Introduction to Programming – 4 Operators
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.
Chapter 3 Operators and Expressions
Chapter 7 Expressions and Assignment Statements.
Operators In Java Programming By Rajanikanth B.
OPERATORS in C Programming
Operator King Saud University
Expressions and Assignment Statements
Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a language-specific syntactical token.
OPERATORS in C Programming
Presentation transcript:

Chapter 4: Expression and Operator

Expression: Definition An expression is any legal combination of symbols that represents a value. Each programming language and application has its own rules for what is legal and illegal. For example, in the C language x+5 is an expression Every expression consists of at least one operand and can have one or more operators. Operands are values, whereas operators are symbols that represent particular actions. In the expression In x + 5, x and 5 are operands, and + is an operator.

Operator: Definition An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators − Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Increment/decrement operator Misc Operators

Arithmetic Operator Operator that performs addition, subtraction, multiplication and division C programming has following binary arithmetic operator Arithmetic Unary operator are + and -

Binary Arithmetic Operator: Example

Unary Arithmetic Operator: Example

Arithmetic Operator precedence and associativity If more than one operators are involved in an expression, C language has a predefined rule of priority for the operators. This rule of priority of operators is called operator precedence. i + j * k equivalent to i + (j * k) or (i + j) * k

Arithmetic Operator Precedence Highest + - (unary) * / % Lowest + - (binary) Listed on same line same precedence

Arithmetic Operator Associativity When operator with same precedence came then associativity matters Left associative if it groups from left to right. Binary arithmetic operator are left associative Right associative if it groups from right to left. The unary operator (+, -) are right associative

Assignment Operator Assigns values from left to right variable = is simple assignment operator If different data type then left operand data type is converted to right.

Assignment Operator Contd.. Assignment operator can be chained together Eg. i=j=k=0; = is right associative thus- i=j=k=0 is equivalent to i=(j=(k=0)); What is assigned to f? int I; float f; f=i=3.2f

Compound Assignment Compound assignment allows to shorten statement Common compound assignment operator are Has same precedence as =

Increment and Decrement Operator Increases and decreases value by 1. Can simple done by using compound statement i=i+1;  i+=1; j=j-1;  j+=1; But C provided ++ and -- operator which shorten even further Can be used on two way with two different meaning prefix and postfix

Prefix and Postfix increment / decrement Eg. Same for -- operator

More Example What are value of i, j and k ?

Expression Evaluation

Expression Statement Any expression by appending semicolon is turned into statement i++; i+j; (do nothing statement)

Other Operator Relational and logical operator