More about Numerical Computation CS-2301, B-Term 20091 More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.

Slides:



Advertisements
Similar presentations
Operators and Expressions Operators are symbols that produce a result based on some rules. Examples: +, -, =, > and
Advertisements

IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Lecture 071 CS 192 Lecture 7 Winter 2003 December 15-16, 2003 Dr. Shafay Shamail.
Numerical Computation Review and Continuation CS-2301, B-Term Numerical Computation in C Review and Continuation CS-2301, System Programming for.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
Loose endsCS-2301, B-Term “Loose Ends” CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Expressions and Operators Program Style.
"Loose ends"CS-2301 D-term “Loose Ends” CS-2301 System Programming C-term 2009 (Slides include materials from The C Programming Language, 2 nd edition,
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Primitive Data Types There are exactly eight primitive data types in Java four of them represent integers: byte (class Byte), short (class Short), int.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
Expressions An expression is a sequence of operands and operators that reduces to a single value expression operator operand An operator is a language-specific.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations System-oriented Programming, B. Hirsbrunner,
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
Expressions, Data Conversion, and Input
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
OperatorstMyn1 Operators The sequence in which different operators in an expression are executed is determined by the precedence of the operators. Operators.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 2 part #4 Operator
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
CHAPTER 2 PART #4 OPERATOR 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101 By: Asma Alosaimi Edited.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
C Programming Lecture 6 : Operators Lecture notes : courtesy of Ohio Supercomputing Center, and Prof. Woo and Prof. Chang.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
15-Nov-15 All the Operators. operators.ppt 2 Precedence An operator with higher precedence is done earlier (precedes) one with lower precedence A higher.
Bit Fields & Bitwise Operations CS-2303, C-Term Bit Fields & Bitwise Operations CS-2303 System Programming Concepts (Slides include materials from.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
Expressions and Operators in C. Expressions and Operators Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); Two types: – Function calls – The expressions.
Operators & Expressions
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
Free Ebooks Download Mba Ebooks By Edhole Mba ebooks Free ebooks download
Expression and Operator. Expressions and Operators u Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); u Two types: –Function calls –The expressions formed.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2012 CMPE-013/L Operators Gabriel Hugh Elkaim Spring 2012.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Operator Kinds of Operator Precedence of Operator Type Casting.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
CSE 220 – C Programming Expressions.
Lecture 3 Java Operators.
Chap. 2. Types, Operators, and Expressions
Tokens in C Keywords Identifiers Constants
Assignment and Arithmetic expressions
Operators and Expressions
Conversions of the type of the value of an expression
All the Operators 22-Nov-18.
More about Numerical Computation
All the Operators 4-Dec-18.
Chapter-3 Operators.
Lectures on Numerical Methods
Bit Fields & Bitwise Operations
Differences between Java and C
Chapter 3 Operators and Expressions
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Homework Finishing Chapter 2 of K&R. We will go through Chapter 3 very quickly. Not a lot is new. Questions?
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
Operator King Saud University
Presentation transcript:

More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie and from C: How to Program, 5 th and 6 th editions, by Deitel and Deitel)

More about Numerical Computation CS-2301, B-Term Reading Assignment Chapter 2 of Kernighan & Ritchie

More about Numerical Computation CS-2301, B-Term More Numerical Operators Relational operators –, >=, ==, != –Return 0 if false, 1 if true Let int a = 3; Then a = 3 returns 1 a == 3 returns 1 a != 3 returns 0

More about Numerical Computation CS-2301, B-Term More Numerical Operators Relational operators –, >=, ==, != –Return 0 if false, 1 if true Let int a = 3; Then a = 3 returns 1 a == 3 returns 1 a != 3 returns 0 Relational operators are not special in C. They are just like any other operators in expressions

More about Numerical Computation CS-2301, B-Term Precedence of Relational Operators Comparisons: lower than arithmetic operators Equality-inequality: lower than comparisons See Table 2-1, p.53 Examples i < lim - 1 means i < (lim – 1) X + (y >= 3) returns the value X (when y = 3 )

More about Numerical Computation CS-2301, B-Term Increment & Decrement Operators ++x, --x, x++, x-- Increments or decrements x by 1 ++x – increments x, returns new value of x x++ – increments x, returns old value of x Used in many situations, especially for loops --x – decrements x, returns new value of x x-- – decrements x, returns old value of x High precedence than *, /, % –Associates right to left

More about Numerical Computation CS-2301, B-Term Bitwise Operations & – bitwise AND | – bitwise OR (inclusive) ^ – bitwise exclusive OR << – left shift Same as multiplying by 2 (i.e., fills low-order bits with zeros) >> – right shift Machine dependent fill on left, depends upon sign bit ~ – one’s complement May only be applied to integral types i.e., int, short, long, char signed or unsigned

More about Numerical Computation CS-2301, B-Term Conditional Expressions expr 1 ? expr 2 : expr 3 –Evaluate expr 1. –If result is true, evaluate and return expr 2 –Otherwise evaluate and return expr 3 Example, –z = (a < b) ? a : b –Assigns z the value of a if a < b, or b otherwise See tricky code at end of §2.11 –For use in Programming Assignment #2

More about Numerical Computation CS-2301, B-Term Assignment Operator (yet again) location += expression means –Add expression to the value at location and assign the result back into the same location Similarly for -=, *=, /=, %=, ^=. |=, >= E.g., x *= a is the same as x = x * a y /= b is the same as y = y * b z <<= 3 is the same as z = z << 3 Exceptions will become apparent later in the course

More about Numerical Computation CS-2301, B-Term Type Conversion May be automatic or explicit See §2.7 Automatic, for signed operands:– If either is long double, convert other to long double Else if either is double, convert other to double Else if either is float, convert other to float Otherwise, convert char and short to int and then if either is long, convert other to long I.e., “promote” numerical types from lower to higher

More about Numerical Computation CS-2301, B-Term Type Conversion (continued) Automatic type conversion of unsigned integer values is Tricky and Machine dependent

More about Numerical Computation CS-2301, B-Term Explicit Type Conversion Definition – cast A unary operator applied to an expression to explicitly force the value to a particular type Represented as (type) expression High precedence, equal to unary operators Associates right-to-left Example (int) sqrt(2*pi) Converts the square root of 2π to an integer and truncates the fractional part (i.e., no rounding)

More about Numerical Computation CS-2301, B-Term Questions? Read or review Chapter 2