# Lecture 4 CSE July 1992

Size: px
Start display at page:

Transcription

1 Lecture 4 CSE July More Operators C has many operators. Some of them, like +, are binary, which means that they require two operands, as in Others are unary, which means they require only one operand. We ll see an example of this in section Arithmetic Arithmetic operators include +, -, *, and / for addition, subtraction, multiplication, and division. Division is a little odd: Its semantics change depending on the types of its operands. If both operands are <int>s, then / represents integer division, in which the fractional part of the result is discarded. For example, the value of the expression 13/5 is 2. % denotes the modulus operator: If a and b are integer expressions, then a%b is the remainder when a is divided by b. For example, the value of the expression 13 % 5 is 3, because 3 is the remainder when you divide 13 by 5. If one of the operands is an expression whose value isn t of integer type, that s an error and the compiler won t compile the program. 1.2 Assignment += is an assignment operator. Like =, its left operand must be an lvalue. x += 2 means the same thing as x = x + 2. It s more natural to think Add 2 to x and to write x += 2; than it is to think Get x, add 2, and put it back. and write x = x + 2;. Furthermore, in an expression like yyval[yypv[p3+p4] + yypv[p1+p2]] += 2 1

2 CSE 110 Lecture Notes Mark Jason Dominus 2 the assignment operator makes the code easier to understand, since the reader doesn t have to check painstakingly that two long expressions are the same, or to wonder why they re not. 1 Similarly, there are -=, *=, /=, %= operators, all defined analogously. 1.3 Increment and Decrement Adding one to something is such a common operation that there s a special name for it and yet another notation for it. Adding 1 to a quantity is called incrementing it. There s a special increment operator, ++. If we write x++ or ++x in an expression, then, sometime before the computer executes the next statement, it will add 1 to the value stored at x. 2 The values of x++ and ++x differ, however: if x is 12, then the value of x++ is 12 and the value of ++x is 13. The notion is that if you use ++x, the compiler increments x before getting its value, and if you use x++, the compiler increments x after geting its value. So if the value of x is 119, then after y = x++ ; y would be 119 and x would be 120, but after y = ++x ; y would be 120 and x would be 120. When the compiler actually chooses to do the increment is None of Your Business, as long as the increment happens before the next statement. 3 Question: What happens if x is 119, and we do: y = x++ + x++ ;? Depending on when the incrementing actually happens, y might get 238, or 239, right? Wrong. For various technical reasons the standard says that if you try to modify the same object twice in one statement, 4 you get undefined behavior the compiler is allowed to do whatever it likes, including nothing, printing a warning, erasing itself, or teleporting elephants into the room. Similarly 1 I swiped this example from The C Programming Language, by Kernighan and Ritchie. 2 Of course, when we say the value stored at x, we are implying that x is an lvalue you can t do 4++ to increment the value of 4; the compiler will complain. 3 Actually it has to happen before the next sequence point. We know about two kinds of sequence points: semicolons are sequence points, and also there is a sequence point just before every function call. 4 Really it says twice without a sequence point in between.

3 CSE 110 Lecture Notes Mark Jason Dominus 3 x = x++ ; is undefined. On the other hand, if x is 2, then y = x * x++ ; is perfectly legal, (x and y are each modified only once before the end of the statement) and might assign y the value 4 or the value 6, depending on whether the compiler does the increment before or after it evaluates the first x. In general it s best to avoid such situations. There is a -- operator, which is just like ++, except that it subtracts 1 instead of adding 1. This is called decrementing. 1.4 Precedence Consider this expression: 2 * does the compiler do 2 * 3 first and then add 4, yielding 10? Or does it do first and then multiply by 2, yielding 14? The rules are consistent with regular mathematics: Multiplication and division (meaning *, /, and %) happen before + and -. So the example above evaluates to 10. Assignment happens way late, after almost everything else, because if you write x = y + 4 ; you never ever mean that you want to store the value of y in x and then add 4 to that result you always mean that you want to add 4 to the value in y and then store that result into x. As in mathematics, expressions in parentheses (( and )) get evaluated first. So the value of is * ( ) ++ and -- have higher precedence than most other things, including everything we ve seen so far. That s so that the ++ in y * x++ applies just to the x and not to the y * x.

4 CSE 110 Lecture Notes Mark Jason Dominus 4 2 The Preprocessor Before the compiler starts in on its work in earnest, it transforms your program a little. On some systems this transformation is done by a separate program, called a preprocessor, but in Turbo C++, the preprocessor is built into the compiler. There are three important transformations and a few unimportant ones that we won t discuss. 2.1 Macros If your source code contains a line like #define PI the preprocessor defines a macro. What this means is that from now on, every time it sees the symbol PI, it will replace it with the sequence The compiler proper will never find out about PI at all; as far as it s concerned, you wrote out in full every time. You can use this for three things: You can use it to clarify the code, by writing things like PI, rather than all over the place. You can use it to set up manifest constants that might change over time. For example, suppose you are writing accounting software for an insurance company; the medical insurance deductible is \$200, and you want to compute the payment. You could write payment = claims ; but then if the deductible ever changed, you d have to go and find all the 200 s in your code and change every one. Worse, it might be that not every 200 is actually a deductible you d have to decide which ones to change. It s much better to do #define DEDUCTIBLE 200 and then you can write payment = claims - DEDUCTIBLE ; and if you need to change the deductible, you just change it in the #define directive and nowhere else. You can use the macro facility to make your code into an unreadable horror. We will not see an example of how to do this.

6 CSE 110 Lecture Notes Mark Jason Dominus 6 the */, and everything in between with blank space, which the compiler ignores. It s too early for an enormous rant about the importance and proper style of comments, but we ll have several later. 3 Conditions If a program did the same thing every time we ran it, it wouldn t be useful. We have to have a way to perform certain actions only when certain conditions are true. 3.1 The if Statement The if statement has this form: if (condition) statement The condition is just an expression. We say that the condition is false if the value of the expression is zero, and we say that the condition is true otherwise. To execute an if statement, the computer first evaluates the expression to decide if the condition is true or not. If the condition is true, the computer executes the statement. Otherwise, it doesn t. The statement could be a compound statement, or it could even be another if statement. 3.2 Relational Operators C provides operators for comparing numbers. The operator == tests two expressions for equality, for example. The expression a == b has the value 0 if a and b are not equal and 1 if they are equal. So we can write if ( a == b ) printf("a and b are equal\n"); If a and b are equal, the expression a == b evaluates to 1, so the condition is true, and the printf statement gets executed. But otherwise, a == b evaluates to 0, so the condition is false and the printf is not executed. a!= b is true when the value of expression a is not equal to the value of expression b. Similarly, we have <, >, <=, and >=, for testing whether one

7 CSE 110 Lecture Notes Mark Jason Dominus 7 expression s value is less than another s, greater than another s, less than or equal to another s, or greater than or equal to another s. Relational operators have low precedence, just before assignments, but after arithmetic. 3.3 Boolean Operators Suppose we want the user to enter an integer between 1 and 10, inclusive. We want to write some code to print a rude message if the user didn t do what we wanted. Suppose the user s number is stored in the variable x Then we could write if ( x < 1 ) <print rude message> ; if ( x > 10 ) <print rude message> ; but then the code to print the rude message is the same both times. That s bad, because someday someone is going to change one and not the other, and then the program will have different behavior where it used to have the same behavior; or else someday both statements might break 7 and someone might fix only one of them by mistake. A principal rule of programming is to never ever have two pieces of code to do the same thing. Fortunately there s a better way to accomplish what we want: if ( x<1 x>10 ) <print rude message> ; reads as or, so we say if x is less than 1 or x is greater than requires two operands, and an expression with an operator is true if either of its operands are true, false if neither is true. has a special property: it short-circuits. In the example above, suppose the value of x is 0. The computer compares x with 1, and finds that x < 1 is true, and so we already know that the rude message will be printed. There s no longer any reason to computer whether or not x > 10 is true; either way we ll print the message. And in fact in C when the computer is evaluating an expression, if the left-hand operand is true, then the computer never evaluates the right-hand one at all. 7 Maybe because the print function changed or something.

8 CSE 110 Lecture Notes Mark Jason Dominus 8 Similarly, there s a && operator, which is pronounced and. For example: if ( x>=1 && x<=10 ) <print polite message> ; If x is greater than or equal to 1 and x is less than or equal to 10, then print the polite message. An expression with && is true if both its operands are true, false otherwise. && also short-circuits, so if x is 0 in the example above, then the computer will only bother to evaluate the x >= 1 part above; since that part is false, it already knows that the whole && expression is false, and there s no point in evaluating the x <= 10 part. and && are called logical operators because they operate on logical conditions such as x < 10, rather than on raw numbers like 12. There is one other logical operator:!, pronounced not.! is a unary operator; it takes only one operand. When the computer wants to evaluate something like!x, it first evaluates x, and then if x is true,!x is false, and vice-versa.! has higher precedence than anything else we ve seen yet. && and have lower precedence than anything except assignment. && has higher precedence than, which is consistent with conventional mathematics There is a table of operator precedence in your text, on pages Incidentally, && and are both sequence points.

### CMSC 104 -Lecture 6 John Y. Park, adapted by C Grasso

CMSC 104 -Lecture 6 John Y. Park, adapted by C Grasso 1 Topics #define Arithmetic Operators Assignment Operators Operator Precedence Evaluating Arithmetic Expressions Incremental Programming 2 Preprocessor

### 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.

### Programming for Engineers Introduction to C

Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

### C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

C++ PROGRAMMING For Industrial And Electrical Engineering Instructor: Ruba A. Salamh CHAPTER TWO: Fundamental Data Types Chapter Goals In this chapter, you will learn how to work with numbers and text,

### UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2012 Lab 3 Matrix Math Introduction Reading In this lab you will write a

### CS102: Variables and Expressions

CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of

### 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.

### 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

### Lecture 19 CSE August You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii.

Lecture 19 CSE 110 5 August 1992 You taught me Language, and my profit on t is I know how to curse. William Shakspere, The Tempest, I, ii. 1 Left-Over Language Features Today was the day we saw the last

### CS16 Week 2 Part 2. Kyle Dewey. Thursday, July 5, 12

CS16 Week 2 Part 2 Kyle Dewey Overview Type coercion and casting More on assignment Pre/post increment/decrement scanf Constants Math library Errors Type Coercion / Casting Last time... Data is internally

### Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships

### Signed umbers. Sign/Magnitude otation

Signed umbers So far we have discussed unsigned number representations. In particular, we have looked at the binary number system and shorthand methods in representing binary codes. With m binary digits,

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/C++ Programming for Engineers: Working with Integer Variables

C/C++ Programming for Engineers: Working with Integer Variables John T. Bell Department of Computer Science University of Illinois, Chicago Preview Every good program should begin with a large comment

### 9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

### Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

### The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

### GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

### Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

### c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

### Full file at C How to Program, 6/e Multiple Choice Test Bank

2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

### CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

CS125 : Introduction to Computer Science Lecture Notes #4 Type Checking, Input/Output, and Programming Style c 2005, 2004, 2002, 2001, 2000 Jason Zych 1 Lecture 4 : Type Checking, Input/Output, and Programming

### Formatting & Style Examples

Formatting & Style Examples The code in the box on the right side is a program that shows an example of the desired formatting that is expected in this class. The boxes on the left side show variations

### Lecture 12 CSE July Today we ll cover the things that you still don t know that you need to know in order to do the assignment.

Lecture 12 CSE 110 20 July 1992 Today we ll cover the things that you still don t know that you need to know in order to do the assignment. 1 The NULL Pointer For each pointer type, there is one special

### Section we will not cover section 2.11 feel free to read it on your own

Operators Class 5 Section 2.11 we will not cover section 2.11 feel free to read it on your own Data Types Data Type A data type is a set of values and a set of operations defined on those values. in class

### COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,

### 1. Variables 2. Arithmetic 3. Input and output 4. Problem solving: first do it by hand 5. Strings 6. Chapter summary

Topic 2 1. Variables 2. Arithmetic 3. Input and output 4. Problem solving: first do it by hand 5. Strings 6. Chapter summary Arithmetic Operators C++ has the same arithmetic operators as a calculator:

### Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### The C++ Language. Arizona State University 1

The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

### 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

### Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

### Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

### Fundamental of Programming (C)

Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

### 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

### 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

### CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables

### CS125 : Introduction to Computer Science. Lecture Notes #11 Procedural Composition and Abstraction. c 2005, 2004 Jason Zych

CS125 : Introduction to Computer Science Lecture Notes #11 Procedural Composition and Abstraction c 2005, 2004 Jason Zych 1 Lecture 11 : Procedural Composition and Abstraction Solving a problem...with

### Chapter 2 Basic Elements of C++

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

### Compilation and Execution Simplifying Fractions. Loops If Statements. Variables Operations Using Functions Errors

First Program Compilation and Execution Simplifying Fractions Loops If Statements Variables Operations Using Functions Errors C++ programs consist of a series of instructions written in using the C++ syntax

### QUIZ: What value is stored in a after this

QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer

### These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

### 2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Expressions and Operators in C (Partially a Review) Expressions are Used

### Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators

Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators Formatted Input and Output The printf function The scanf function Arithmetic and Assignment Operators Simple Assignment Side Effect

### COP 3275: Chapter 04. Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA

COP 3275: Chapter 04 Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA Operators C emphasizes expressions rather than statements. Expressions are built from variables, constants, and

### A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object

### Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 17 Switch Statement (Refer Slide Time: 00:23) In

### 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

### CSCE 120: Learning To Code

CSCE 120: Learning To Code Manipulating Data I Introduction This module is designed to get you started working with data by understanding and using variables and data types in JavaScript. It will also

### CS112 Lecture: Working with Numbers

CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations

### 3. Simple Types, Variables, and Constants

3. Simple Types, Variables, and Constants This section of the lectures will look at simple containers in which you can storing single values in the programming language C++. You might find it interesting

### CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

### Fundamentals of Programming

Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

### Language Reference Manual simplicity

Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

### 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

### Variables, expressions and statements

Variables, expressions and statements 2.1. Values and data types A value is one of the fundamental things like a letter or a number that a program manipulates. The values we have seen so far are 2 (the

### Lecture 7: Primitive Recursion is Turing Computable. Michael Beeson

Lecture 7: Primitive Recursion is Turing Computable Michael Beeson Closure under composition Let f and g be Turing computable. Let h(x) = f(g(x)). Then h is Turing computable. Similarly if h(x) = f(g 1

### Divisibility Rules and Their Explanations

Divisibility Rules and Their Explanations Increase Your Number Sense These divisibility rules apply to determining the divisibility of a positive integer (1, 2, 3, ) by another positive integer or 0 (although

### CSE 374 Programming Concepts & Tools

CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 8 C: Miscellanea Control, Declarations, Preprocessor, printf/scanf 1 The story so far The low-level execution model of a process (one

### Implementing an Algorithm for Boomerang Fraction Sequences in Python

Introduction Implementing an Algorithm for Boomerang Fraction Sequences in Python We ve all encountered maze problems, where the challenge is to find a path through a labyrinth from a starting point to

### CS 142 Style Guide Grading and Details

CS 142 Style Guide Grading and Details In the English language, there are many different ways to convey a message or idea: some ways are acceptable, whereas others are not. Similarly, there are acceptable

### Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

### printf( Please enter another number: ); scanf( %d, &num2);

CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

### LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

### Fundamentals of Programming CS-110. Lecture 3

Fundamentals of Programming CS-110 Lecture 3 Operators Operators Operators are words or symbols that cause a program to do something to variables. OPERATOR TYPES: Type Operators Usage Arithmetic + - *

### CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started

CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started Handout written by Julie Zelenski, Mehran Sahami, Robert Plummer, and Jerry Cain. After today s lecture, you should run home and read

### Operators And Expressions

Operators And Expressions Operators Arithmetic Operators Relational and Logical Operators Special Operators Arithmetic Operators Operator Action Subtraction, also unary minus + Addition * Multiplication

### 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

### JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

### Program Fundamentals

Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

### Lecture 16 CSE July 1992

Lecture 16 CSE 110 28 July 1992 1 Dynamic Memory Allocation We are finally going to learn how to allocate memory on the fly, getting more when we need it, a subject not usually covered in introductory

### Operators. Java operators are classified into three categories:

Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

### Objectives. In this chapter, you will:

Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

### 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

### Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

Plan for the rest of the semester: Programming We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems. We saw earlier that computers

### Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical

### 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

### Chapter 6. Loops. Iteration Statements. C s iteration statements are used to set up loops.

Chapter 6 Loops 1 Iteration Statements C s iteration statements are used to set up loops. A loop is a statement whose job is to repeatedly execute some other statement (the loop body). In C, every loop

### CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

### Arithmetic Expressions in C

Arithmetic Expressions in C Arithmetic Expressions consist of numeric literals, arithmetic operators, and numeric variables. They simplify to a single value, when evaluated. Here is an example of an arithmetic

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

C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

### } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.

### UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . \$, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

### Annotation Annotation or block comments Provide high-level description and documentation of section of code More detail than simple comments

Variables, Data Types, and More Introduction In this lesson will introduce and study C annotation and comments C variables Identifiers C data types First thoughts on good coding style Declarations vs.

### (Refer Slide Time 6:48)

Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 8 Karnaugh Map Minimization using Maxterms We have been taking about

### CS Introduction to Data Structures How to Parse Arithmetic Expressions

CS3901 - Introduction to Data Structures How to Parse Arithmetic Expressions Lt Col Joel Young One of the common task required in implementing programming languages, calculators, simulation systems, and

### First-Order Translation Checklist

CS103 Winter 2019 First-Order Translation Checklist Cynthia Lee Keith Schwarz In this handout, we ve distilled five specific points that you should check in your first-order logic statements before submitting

### 4. Java Project Design, Input Methods

4-1 4. Java Project Design, Input Methods Review and Preview You should now be fairly comfortable with creating, compiling and running simple Java projects. In this class, we continue learning new Java

### LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

LESSON VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT PROF. JOHN P. BAUGH PROFJPBAUGH@GMAIL.COM PROFJPBAUGH.COM CONTENTS INTRODUCTION... Assumptions.... Variables and Data Types..... Numeric Data Types:

### Have examined process Creating program Have developed program Written in C Source code

Preprocessing, Compiling, Assembling, and Linking Introduction In this lesson will examine Architecture of C program Introduce C preprocessor and preprocessor directives How to use preprocessor s directives

### 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

### CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

### Reliable programming

Reliable programming How to write programs that work Think about reliability during design and implementation Test systematically When things break, fix them correctly Make sure everything stays fixed

### Basics of Java Programming

Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

### Work relative to other classes

Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language