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


 Augustine Pope
 1 years ago
 Views:
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 Shortcircuit 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 userdefined 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 ifthenelse statement 6 2
3 Operand Evaluation Order When do we evaluate operand? Variables are evaluated by fetching their values from memory Constants Sometimes, constants are evaluated by fetching its value from memory; At other times, it is part of the machine language instruction Parenthesized expressions If operand is a parenthesized expression, all operators it contains must be evaluated before its value can be used as an operand Function calls Must be evaluated before its value can be used as an operand 7 Operand Evaluation Order Functional Side Effects When function changes one of its params/global variable a + fun(a) If fun does not have the side effect of changing a, then the order evaluation of the two operands, a and fun(a), does not matter If fun does have the side effect of changing a, order of evaluation matters Two Possible Solutions : Disallow functional side effects in the language definition No twoway parameters in functions No nonlocal references in functions Advantage: it works! Disadvantage: No more flexibility Write language definition to demand fixed operand evaluation order Disadvantage: limits some compiler optimizations 8 Overloaded Operators Multiple use of an operator E.g., use + for integer addition and floatingpoint addition Some drawbacks of operator overloading May affect readability E.g., the ampersand (&) operator in C is used to specify bitwise logical AND operation Address of a variable May affect reliability Program does not behave the way we want int x, y; float z; z = x / y Problem can be avoided by introducing new symbols (e.g., Pascal s div for integer division and / for floating point division) C++ and Ada allow userdefined overloaded operators Potential problems: Users can define nonsense operations Readability may suffer, even when the operators make sense E.g., use + to mean multiplication 9 3
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 mixedmode 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) Cbased 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 Shortcircuit 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 shortcircuit evaluation index = 1; while (index <= length) && (LIST[index]!= value) index++; C, C++, and Java: use shortcircuit evaluation for usual Boolean operators (&& and ), also provide bitwise Boolean operators that are not short circuit (& and ) 14 Short Circuit Evaluation Ada: Nonshortcircuit: AND OR shortcircuit: AND THEN OR ELSE Index = 1; while (Index <= Listlen) and then (List(Index) /= Key) loop Index = Index + 1; end loop; Shortcircuit 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, Modula2, 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: Oneway selection statements Twoway selection statements Nway (multiple) selection statements Nested selection statements? 22 Selection Statements SingleWay 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 Twoway 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 threeway 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 ShortCircuit Evaluation Assignment Statements
More informationChapter 7. Expressions and Assignment Statements ISBN
Chapter 7 Expressions and Assignment Statements ISBN 0321330250 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions ShortCircuit
More informationChapter 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 ShortCircuit Evaluation Assignment
More informationChapter 7. Expressions and Assignment Statements (updated edition 11) ISBN
Chapter 7 Expressions and Assignment Statements (updated edition 11) ISBN 0321493621 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean
More informationExpressions 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
More informationSoftware 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
More informationChapter 7. Expressions and Assignment Statements ISBN
Chapter 7 Expressions and Assignment Statements ISBN 0321493621 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions ShortCircuit
More informationChapter 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 ShortCircuit Evaluation Assignment
More informationRelational 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 ShortCircuit Evaluation Assignment
More informationExpression 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 Shortcircuit evaluation of conditions
More informationChapter 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
More information9/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 Shortcircuit evaluation of conditions
More informationChapter7 Expression and Assignment Statement. Introduction
Chapter7 Expression and Assignment Statement Arithmetic Expressions Overloaded Operators Boolean Expressions ShortCircuit Evaluation Assignment Statements MixedMode Assignment Introduction Fundamental
More informationConcepts of Programming Languages
Concepts of Programming Languages COMP322 Fall 2012/2013 11 Textbook ISBN 0321493621 Chapter 1 Preliminaries ISBN 0321493621 Chapter 1 Topics Reasons for Studying Concepts of Programming Languages
More informationExpressions 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
More informationControl Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. Oneway Twoway Multiway
Control Structures In Text: Chapter 8 1 Control structures Selection Oneway Twoway Multiway Iteration Countercontrolled Logicallycontrolled Gotos Guarded statements Outline Chapter 8: Control Structures
More informationChapter 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
More informationChapter 8. StatementLevel Control Structures
Chapter 8 StatementLevel Control Structures Levels of Control Flow Within expressions Among program units Among program statements Copyright 2012 AddisonWesley. All rights reserved. 12 Control Structure
More informationChapter 8 StatementLevel Control Structures
Chapter 8 StatementLevel 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
More informationModule 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
More informationStatement 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
More informationChapter 8. StatementLevel Control Structures
Chapter 8 StatementLevel Control Structures Chapter 8 Topics Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions 12 Levels of Control Flow Within
More informationChapter 8. StatementLevel Control Structures
Chapter 8 StatementLevel Control Structures Chapter 8 Topics Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions Copyright 2009 AddisonWesley.
More informationMotivation 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
More informationChapter 8. StatementLevel Control Structures ISBN
Chapter 8 StatementLevel Control Structures ISBN 0321493621 Chapter 8 Topics Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions Copyright 2012
More informationLECTURE 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)
More informationReview of the C Programming Language
Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22Apr2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the
More informationCh. 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
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if  statement ifelse  statement switch  statement? : opertator Nested conditional statements Repetitive statements
More informationProgramming 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
More informationG Programming Languages  Fall 2012
G22.2110003 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
More informationOperators 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
More informationECE 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
More informationDefinition: 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.
More informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and objectoriented Classes and instances (ie
More informationLECTURE 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
More informationOutline. 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
More informationAnnouncements. Lab Friday, 12:30 and 34:30 in Boot your laptop and start Forte, if you brought your laptop
Announcements Lab Friday, 12:30 and 34:30 in 26152 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
More informationC++ 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
More informationReview 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 4Sep2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights
More informationCSc 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
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
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
More informationChapter 7. Additional Control Structures
Chapter 7 Additional Control Structures 1 Chapter 7 Topics Switch Statement for MultiWay Branching DoWhile Statement for Looping For Statement for Looping Using break and continue Statements 2 Chapter
More informationIntroduction to Programming Using Java (98388)
Introduction to Programming Using Java (98388) 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;
More informationProgramming for Engineers Iteration
Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,./0 class average = 2345067 893/0298 Grade and number of students can be integers
More informationChapter 8 StatementLevel Control Structure
Chapter 8 StatementLevel Control Structure To make programs more flexible and powerful: Some means of selecting among alternative control flow paths. Selection statement (conditional statements) Unconditional
More informationControl 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
More informationMIDTERM 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
More informationSTUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, ifelse 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 highlevel
More informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Shortcircuiting main method public static
More informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Shortcircuiting main method public static
More informationChapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.
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
More informationC 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
More informationOperators 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
More informationJava 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
More informationC++ 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
More informationPrinciples 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
More informationObjectives. 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)
More informationo Counter and sentinel controlled loops o Formatting output o Type casting o Topdown, 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 Topdown, stepwise
More information9/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
More informationNumerical 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.
More informationChapter 5 Names, Binding, Type Checking and Scopes
Chapter 5 Names, Binding, Type Checking and Scopes Names  We discuss all userdefined names here  Design issues for names: Maximum length?  Are connector characters allowed?  Are names case sensitive?
More informationOperators 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
More informationUnit 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.
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 21 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationOperators 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
More informationChapter 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)
More information5. 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
More informationTwo 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 informationMore 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
More informationIterative Statements. Iterative Statements: Examples. CounterControlled Loops. ICOM 4036 Programming Languages StatementLevel Control Structure
ICOM 4036 Programming Languages StatementLevel Control Structure Selection Statement Iterative Statements Unconditional Branching Guarded Commands This lecture covers review questions 816 This lecture
More informationJava 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,
More informationThe 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
More informationThe 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
More information1.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
More informationSOFTWARE 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:
More informationCSC 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
More informationOperators & 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.
More informationControl 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
More informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and objectoriented Classes and instances (ie
More informationPrinceton 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
More informationContinued 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
More informationPrimitive Types. Four integer types: Two floatingpoint 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 floatingpoint types: float double (most common) One character type: char One boolean type: boolean 1 2 Primitive Types, cont.
More informationTypes. 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
More informationCOP4020 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
More informationOperators. Lecture 3 COP 3014 Spring January 16, 2018
Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special builtin symbols that have functionality, and work on operands operand an input to an operator Arity  how many operands an operator
More informationChapter 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
More informationThe 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
More informationLECTURE 3 C++ Basics Part 2
LECTURE 3 C++ Basics Part 2 OVERVIEW Operators Type Conversions OPERATORS Operators are special builtin symbols that have functionality, and work on operands. Operators are actually functions that use
More informationType 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
More informationArithmetic 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:  +
More informationThe 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
More informationCSE 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
More informationC++ 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
More informationIntroduction. 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
More informationExpressions 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
More informationFlow 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
More informationOverview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D1
CPE 101 mod/reusing slides from a UW course Overview (4) Lecture 4: Arithmetic Expressions Arithmetic expressions Integer and floatingpoint (double) types Unary and binary operators Precedence Associativity
More informationIPCoreL. Phillip Duane Douglas, Jr. 11/3/2010
IPCoreL Programming Language Reference Manual Phillip Duane Douglas, Jr. 11/3/2010 The IPCoreL Programming Language Reference Manual provides concise information about the grammar, syntax, semantics, and
More informationWriting Program in C Expressions and Control Structures (Selection Statements and Loops)
Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague
More information