# CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow

Size: px
Start display at page:

Download "CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow"

Transcription

1 CSE 452: Programming Languages Expressions and Control Flow Outline of Today s Lecture Expressions and Assignment Statements Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-circuit evaluation Assignment Statements Mixed mode assignment 2 Expressions Expressions are the fundamental means of specifying computations in a programming language Types: Arithmetic Relational/Boolean 3 1

2 Arithmetic Expressions Consist of operators, operands, parentheses, and function calls Design issues for arithmetic expressions: What are the operator precedence rules? What are the operator associativity rules? What is the order of operand evaluation? Are there restrictions on operand evaluation side effects? Does the language allow user-defined operator overloading? What mode mixing is allowed in expressions? 4 Arithmetic Expressions Types of operators A unary operator has one operand: - x A binary operator has two operands: x + y Infix: operator appears between two operands Prefix: operator precede their operands A ternary operator has three operands: (x > 10)? 0 : 1 Evaluation Order Operator evaluation order Operand evaluation order 5 Operator Evaluation Order Four rules to specify order of evaluation for operators 1. Operator precedence rules Define the order in which the operators of different precedence levels are evaluated (e.g., + vs * ) 2. Operator associativity rules Define the order in which adjacent operators with the same precedence level are evaluated (e.g., left/right associative) 3. Parentheses Precedence and associativityrules can be overriden with parentheses 4. Conditional Expressions (?: operator in C/C++/Perl) Equivalent to if-then-else statement 6 2

4 Type Conversions Narrowing conversion converts the value of a type to another type that cannot store all the values of the original type e.g., convert double to float Widening conversion converts the value to a type that include at least approximations to all of the values of the original type e.g., convert integers to float 10 Type Conversions Implict/Explicit type conversion Coercion is an implicit type conversion Useful for mixed-mode expression, which contains operands of different types Disadvantage: decreases type error detection ability of compilers In most languages, all numeric types are coerced in expressions, using widening conversions In Ada, there are virtually no coercions in expressions Explicit Type Conversions Often called type casts Ada: Float(Index) -- Index is originally an integer type Java: (int) speed /* speed is float type */ 11 Relational Expressions Relational operator is an operator that compares the values of its two operands Relational expression has two operands and one relational operator Operator symbols used vary somewhat among languages Ada: /= (not equal operator) C-based language:!= Fortran.NE. or <> Javascript and PHP has two additional relational operators: === and!== similar to == and!=, except it is used to prevent coercion E.g., 7 == 7 is true in Javascript but 7 ===7 is false 12 4

5 Boolean Expressions Consist of Boolean variables, Boolean constants, relational expressions, and Boolean operators Boolean Operators: FORTRAN77 FORTRAN90 C Ada.AND..OR..NOT. and or not &&! and or not C has no Boolean type it uses int type with 0 for false and nonzero for true a > b > c is a legal expression 13 Short Circuit Evaluation Short-circuit evaluation of an expression result is determined without evaluating all operands & operators int a = -1, b = 4; if ((a > 0) && (b < 10)) { } Problem: suppose Java did not use short-circuit evaluation index = 1; while (index <= length) && (LIST[index]!= value) index++; C, C++, and Java: use short-circuit evaluation for usual Boolean operators (&& and ), also provide bitwise Boolean operators that are not short circuit (& and ) 14 Short Circuit Evaluation Ada: Non-short-circuit: AND OR short-circuit: AND THEN OR ELSE Index = 1; while (Index <= Listlen) and then (List(Index) /= Key) loop Index = Index + 1; end loop; Short-circuit evaluation exposes the potential problem of side effects in expressions e.g. (a > b) (b++ / 3) (b is changed only when a <= b) 15 5

6 Assignment Statements The assignment operator symbol: = FORTRAN, BASIC, PL/I, C, C++, Java := ALGOLs, Pascal, Modula-2, Ada = can be bad if it is overloaded for the relational operator for equality e.g. (PL/I) A = B = C; 16 Assignment Statements More complicated assignments: Multiple targets (PL/I) A, B = 10 Conditional targets (C, C++, and Java) x = flag? count1 : count2 = 0; Compound assignment operators (C, C++, and Java) sum += next; Unary assignment operators (C, C++, and Java) a++; - count ++; 17 Assignment Statements C, C++, and Java treat = as an arithmetic binary operator e.g. a = b * (c = d * 2 + 1) + 1 This is inherited from ALGOL 68 Assignment as an Expression In C, C++, and Java, the assignment statement produces a result So, they can be used as operands in expressions e.g. while ((ch = getchar()!= EOF) {... } Disadvantage Another kind of expression side effect Exercise: a=1, b=2, c=3, d=4 a = b + (c = d / b++) 1 cout << a <<, << b <<, << c <<, << d << endl 18 6

7 Mixed Mode Assignment In FORTRAN, C, and C++ any numeric value can be assigned to any numeric scalar variable; whatever conversion that is necessary is done In Pascal integers can be assigned to reals, but reals cannot be assigned to integers programmer must specify whether the conversion from real to integer is truncated or rounded In Java, only widening assignment coercions are done In Ada, there is no assignment coercion 19 Control Structures A control structure is a control statement and the statements whose execution it controls Types of control statements: Selection statements Iterative statements Unconditional branching statement Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements 20 Design Issues What control statements should a language have? Can a control structure have multiple entries? Single entry: execution of the code segment begins with the first statement in the segment Multiple entries are possible in languages that include gotos and statement labels Multiple entries may add flexibility to a control construct Can a control structure have multiple exits? 21 7

8 Selection Statements Provides the means for choosing between two or more execution paths in a program Types of Selection Statements: One-way selection statements Two-way selection statements N-way (multiple) selection statements Nested selection statements? 22 Selection Statements Single-Way Examples FORTRAN IF: IF (boolean_expr) statement Problem: can select only a single statement; to select more, a GOTO must be used, as in the following example IF (.NOT. condition) GOTO CONTINUE 23 Selection Statements Two-way selection statements if control_expression then clause else clause Control_expression arithmetic/boolean expressions Clause form Can be single statements or compound statements (statements in a program block) 24 8

9 Selection Statements Nested Selectors if (sum == 0) if (count == 0) result = 0; else result = 1; Which if gets the else? Java's static semantics rule: else goes with the nearest if To force alternative semantics, use compound statement if (sum == 0) { if (count == 0) result = 0; } else result = 1; 25 Selection Statements FORTRAN 90 and Ada solution use special words to resolve semantics of nested selectors e.g. (Ada) if.. then if then else end if end if if.. then if then end if else end if Advantage: flexibility and readability 26 Selection Statements Multiple Selection Constructs C: switch (expression) { case const_expr_1: statement_1; case const_expr_k: statement_k; [default: def_statement;] (optional) } 27 9

10 Selection Statements Early Multiple Selectors: FORTRAN arithmetic IF (a three-way selector) IF (arithmetic expression) N1, N2, N3 Multiple Selection using if: if Expr1 then statement_1 elsif Expr2 then statement_2 else statement_k end if; 28 10

### Expressions & Assignment Statements

Expressions & Assignment Statements 1 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment Statements

### Chapter 7. Expressions and Assignment Statements ISBN

Chapter 7 Expressions and Assignment Statements ISBN 0-321-33025-0 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit

### Chapter 7. Expressions and Assignment Statements

Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

### Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

Chapter 7 Expressions and Assignment Statements (updated edition 11) ISBN 0-321-49362-1 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean

### Expressions and Assignment Statements

Expressions and Assignment Statements Introduction Expressions are the fundamental means of specifying computations in a programming language To understand expression evaluation, need to be familiar with

### Software II: Principles of Programming Languages. Why Expressions?

Software II: Principles of Programming Languages Lecture 7 Expressions and Assignment Statements Why Expressions? Expressions are the fundamental means of specifying computations in a programming language

### Chapter 7. Expressions and Assignment Statements ISBN

Chapter 7 Expressions and Assignment Statements ISBN 0-321-49362-1 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit

### Chapter 7. Expressions and Assignment Statements

Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

### Relational Expressions. Boolean Expressions. Boolean Expressions. ICOM 4036 Programming Languages. Boolean Expressions

ICOM 4036 Programming Languages Ch7. Expressions & Assignment Statements Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

### Expression Evaluation and Control Flow. Outline

Expression Evaluation and Control Flow In Text: Chapter 6 Outline Notation Operator Evaluation Order Operand Evaluation Order Overloaded operators Type conversions Short-circuit evaluation of conditions

### Chapter 7 Expressions and Assignment statements

Chapter 7 Expressions and Assignment statements 1 7.1 Introduction Expressions are the fundamental means of specifying computations in a programming language Semantics of expressions are discussed in this

### 9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

Outline Expression Evaluation and Control Flow In Text: Chapter 6 Notation Operator evaluation order Operand evaluation order Overloaded operators Type conversions Short-circuit evaluation of conditions

### Chapter7 Expression and Assignment Statement. Introduction

Chapter7 Expression and Assignment Statement Arithmetic Expressions Overloaded Operators Boolean Expressions Short-Circuit Evaluation Assignment Statements Mixed-Mode Assignment Introduction Fundamental

### Concepts of Programming Languages

Concepts of Programming Languages COMP322 Fall 2012/2013 1-1 Textbook ISBN 0-321-49362-1 Chapter 1 Preliminaries ISBN 0-321-49362-1 Chapter 1 Topics Reasons for Studying Concepts of Programming Languages

### Expressions and Assignment

Expressions and Assignment COS 301: Programming Languages Outline Other assignment mechanisms Introduction Expressions: fundamental means of specifying computations Imperative languages: usually RHS of

### Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way

Control Structures In Text: Chapter 8 1 Control structures Selection One-way Two-way Multi-way Iteration Counter-controlled Logically-controlled Gotos Guarded statements Outline Chapter 8: Control Structures

### Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements Evolution: - FORTRAN I control statements were based directly on IBM 704 hardware - Much research and argument

### Chapter 8 Statement-Level Control Structures

Chapter 8 Statement-Level Control Structures In Chapter 7, the flow of control within expressions, which is governed by operator associativity and precedence rules, was discussed. This chapter discusses

### Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

### Statement level control structures

1 Statement level control structures CS 315 Programming Languages Pinar Duygulu Bilkent University Control Statements: Evolution 2 FORTRAN I control statements were based directly on IBM 704 hardware Much

### Chapter 8. Statement-Level Control Structures

Chapter 8 Statement-Level Control Structures Chapter 8 Topics Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions 1-2 Levels of Control Flow Within

### Chapter 8. Statement-Level Control Structures

Chapter 8 Statement-Level Control Structures Chapter 8 Topics Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions Copyright 2009 Addison-Wesley.

### Motivation for typed languages

Motivation for typed languages Untyped Languages: perform any operation on any data. Example: Assembly movi 5 r0 // Move integer 5 (some representation) to r0 addf 3.6 r0 // Treat bit representation in

### Chapter 8. Statement-Level Control Structures ISBN

Chapter 8 Statement-Level Control Structures ISBN 0-321-49362-1 Chapter 8 Topics Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions Copyright 2012

### LECTURE 17. Expressions and Assignment

LECTURE 17 Expressions and Assignment EXPRESSION SYNTAX An expression consists of An atomic object, e.g. number or variable. An operator (or function) applied to a collection of operands (or arguments)

### Review of the C Programming Language

Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

### Ch. 7: Control Structures

Ch. 7: Control Structures I. Introduction A. Flow of control can be at multiple levels: within expressions, among statements (discussed here), and among units. B. Computation in imperative languages uses

### Flow Control. CSC215 Lecture

Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements

### Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

### G Programming Languages - Fall 2012

G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

### Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

### ECE 122 Engineering Problem Solving with Java

ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions

### Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values.

Data Types 1 Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Base Data Types All the values of the type are ordered and atomic.

### Ruby: Introduction, Basics

Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

### LECTURE 18. Control Flow

LECTURE 18 Control Flow CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear in a program text. Selection (or alternation): a

### Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how

### Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00

### C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection) Control Structures A computer can proceed: In sequence Selectively (branch) - making

### Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

### CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

CSc 520 Principles of Programming Languages 26 : Control Structures Introduction Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

### Chapter 7. Additional Control Structures

Chapter 7 Additional Control Structures 1 Chapter 7 Topics Switch Statement for Multi-Way Branching Do-While Statement for Looping For Statement for Looping Using break and continue Statements 2 Chapter

### Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

### Programming for Engineers Iteration

Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers

### Chapter 8 Statement-Level Control Structure

Chapter 8 Statement-Level Control Structure To make programs more flexible and powerful: Some means of selecting among alternative control flow paths. Selection statement (conditional statements) Unconditional

### Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an

### MIDTERM EXAMINATION - CS130 - Spring 2003

MIDTERM EXAMINATION - CS130 - Spring 2003 Your full name: Your UCSD ID number: This exam is closed book and closed notes Total number of points in this exam: 120 + 10 extra credit This exam counts for

### STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if- Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a high-level

Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

Chapter 4: Expressions Chapter 4 Expressions 1 Chapter 4: Expressions Operators Expressions are built from variables, constants, and operators. C has a rich collection of operators, including arithmetic

### C expressions. (Reek, Ch. 5) 1 CS 3090: Safety Critical Programming in C

C expressions (Reek, Ch. 5) 1 Shift operations Left shift: value > n Two definitions: logical version: discard the n

### Operators in C. Staff Incharge: S.Sasirekha

Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C

### Java enum, casts, and others (Select portions of Chapters 4 & 5)

Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The

### C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 4: Control Structures I (Selection)

C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 4: Control Structures I (Selection) Objectives In this chapter, you will: Learn about control structures Examine relational

### Principles of Programming Languages. Lecture Outline

Principles of Programming Languages CS 492 Lecture 1 Based on Notes by William Albritton 1 Lecture Outline Reasons for studying concepts of programming languages Programming domains Language evaluation

### Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Objectives Chapter 4: Control Structures I (Selection) In this chapter, you will: Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)

### o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

Last Time Let s all Repeat Together 10/3/05 CS150 Introduction to Computer Science 1 1 We covered o Counter and sentinel controlled loops o Formatting output Today we will o Type casting o Top-down, stepwise

### 9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Outline Name, Scope and Binding In Text: Chapter 5 Names Variable Binding Type bindings, type conversion Storage bindings and lifetime Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur

### Numerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2

Numerical Computing in C and C++ Jamie Griffin Semester A 2017 Lecture 2 Visual Studio in QM PC rooms Microsoft Visual Studio Community 2015. Bancroft Building 1.15a; Queen s W207, EB7; Engineering W128.D.

### Chapter 5 Names, Binding, Type Checking and Scopes

Chapter 5 Names, Binding, Type Checking and Scopes Names - We discuss all user-defined names here - Design issues for names: -Maximum length? - Are connector characters allowed? - Are names case sensitive?

### Operators and Expressions

Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

### Unit 3. Operators. School of Science and Technology INTRODUCTION

INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

### Full file at

Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

### Operators and Expressions:

Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

### Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

Chapter 4: Control Structures I (Selection) In this chapter, you will: Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)

### 5. Control Statements

5. Control Statements This section of the course will introduce you to the major control statements in C++. These control statements are used to specify the branching in an algorithm/recipe. Control statements

### Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Class #07: Java Primitives Software Design I (CS 120): M. Allen, 13 Sep. 2018 Two Types of Types So far, we have mainly been dealing with objects, like DrawingGizmo, Window, Triangle, that are: 1. Specified

### More Programming Constructs -- Introduction

More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

### Iterative Statements. Iterative Statements: Examples. Counter-Controlled Loops. ICOM 4036 Programming Languages Statement-Level Control Structure

ICOM 4036 Programming Languages Statement-Level Control Structure Selection Statement Iterative Statements Unconditional Branching Guarded Commands This lecture covers review questions 8-16 This lecture

### Java Primer 1: Types, Classes and Operators

Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

### The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

### The Arithmetic Operators

The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

### 1.3b Type Conversion

1.3b Type Conversion Type Conversion When we write expressions involved data that involves two different data types, such as multiplying an integer and floating point number, we need to perform a type

### SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

SOFTWARE DEVELOPMENT 1 Operators 2018W (Institute of Pervasive Computing, JKU Linz) OPERATORS Operators are required to form expressions. Depending on the number of operands they take, they are called:

### CSC 533: Organization of Programming Languages. Spring 2005

CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms

### Operators & Expressions

Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

### Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

### Ruby: Introduction, Basics

Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

### Princeton University Computer Science 217: Introduction to Programming Systems The Design of C

Princeton University Computer Science 217: Introduction to Programming Systems The Design of C C is quirky, flawed, and an enormous success. While accidents of history surely helped, it evidently satisfied

### Continued from previous lecture

The Design of C: A Rational Reconstruction: Part 2 Jennifer Rexford Continued from previous lecture 2 Agenda Data Types Statements What kinds of operators should C have? Should handle typical operations

### Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long

Primitive Types Four integer types: byte short int (most common) long Two floating-point types: float double (most common) One character type: char One boolean type: boolean 1 2 Primitive Types, cont.

### Types. What is a type?

Types What is a type? Type checking Type conversion Aggregates: strings, arrays, structures Enumeration types Subtypes Types, CS314 Fall 01 BGRyder 1 What is a type? A set of values and the valid operations

### COP4020 Programming Languages. Control Flow Prof. Robert van Engelen

COP4020 Programming Languages Control Flow Prof. Robert van Engelen Overview Structured and unstructured flow Goto's Sequencing Selection Iteration and iterators Recursion Nondeterminacy Expressions evaluation

### Operators. Lecture 3 COP 3014 Spring January 16, 2018

Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special built-in symbols that have functionality, and work on operands operand an input to an operator Arity - how many operands an operator

### Chapter 3: Operators, Expressions and Type Conversion

101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

### The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

### LECTURE 3 C++ Basics Part 2

LECTURE 3 C++ Basics Part 2 OVERVIEW Operators Type Conversions OPERATORS Operators are special built-in symbols that have functionality, and work on operands. Operators are actually functions that use

### Type Conversion. and. Statements

and Statements Type conversion changing a value from one type to another Void Integral Floating Point Derived Boolean Character Integer Real Imaginary Complex no fractional part fractional part 2 tj Suppose

### Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

### The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

### CSE 431S Type Checking. Washington University Spring 2013

CSE 431S Type Checking Washington University Spring 2013 Type Checking When are types checked? Statically at compile time Compiler does type checking during compilation Ideally eliminate runtime checks

### C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

C++ Basics January 19, 2012 Brian A. Malloy Slide 1 of 24 1. Many find Deitel quintessentially readable; most find Stroustrup inscrutable and overbearing: Slide 2 of 24 1.1. Meyers Texts Two excellent

### Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires

### Expressions and Statements. Department of CSE, MIT, Manipal

Expressions and Statements Control Control: what gets executed, when, and in what order. Abstraction of control: Expression Statement Exception Handling Procedures and functions Expression vs. Statement

### Flow of Control Execution Sequence

Flow of Control Execution Sequence Sequence sequence Decision tree Repetition graph Language Constructs sequence statements (incl Foc) simple / compound decision (1 /2 / n way) if then [else] case / switch

### Overview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D-1

CPE 101 mod/reusing slides from a UW course Overview (4) Lecture 4: Arithmetic Expressions Arithmetic expressions Integer and floating-point (double) types Unary and binary operators Precedence Associativity