Additional C++ Operators ROBERT REAVES. Choosing a Looping Statement  Count-controlled loop, use for loop.  Event-controlled loop whose body should.

Slides:



Advertisements
Similar presentations
Chapter 2: Basic Elements of C++
Advertisements

A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
Compound Operators 03/07/11. More Operators, First Section 4.4.
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.
Chapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++
Data Types, Expressions and Functions (part I)
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
Basic Elements of C++ Chapter 2.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
1 Simple Data Types: Built-in and Use-Defined. 2 Chapter 10 Topics  Built-In Simple Types  Integral and Floating Point Data Types  Using Combined Assignment.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
1 Chapter 10 Simple Data Types: Built- In and User- Defined Dale/Weems.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Java Software Solutions Lewis and Loftus Chapter 5 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. More Programming Constructs.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
Chapter 7 Additional Control Structures. Chapter 7 Topics l Switch Statement for Multi-Way Branching l Do-While Statement for Looping l For Statement.
AEEE 195 – Repetition Structures: Part B Spring semester 2011.
CSIS 113A Lecture 3 Conditional & Switch Glenn Stevenson CSIS 113A MSJC.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 2 Elementary Programming.
Increment Operator To increment a variable X by 1. X+1;X+=;++X; X = 10 Y = X + 1;Y = 11 X += 1;X = 11 Y = ++X + 4;Y = 15.
Week 3 - Wednesday.  What did we talk about last time?  Other C features  sizeof, const  ASCII table  printf() format strings  Bitwise operations.
Simple Data Types: Built-In and User-Defined
C++ How to Program, Late Objects Version, 7/e © by Pearson Education, Inc. All Rights Reserved.
Simple Data Types Built-In and User Defined Chapter 10.
LOOP & Type Conversion. do – while Loop In the while loop, the test expression is evaluated at the beginning of the loop. If the test condition is false.
Chapter 6 Mathematical Operations. 6.1 Mathematical Expressions In mathematics this expression is valid 0 = -4y + 5 It is invalid in programming Left.
Today’s Lecture  Literal  Constant  Precedence rules  More assignment rules  Program Style.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 2: Basic Elements of C++
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
Programming Fundamentals. The setw Manipulator setw changes the field width of output. The setw manipulator causes the number (or string) that follows.
1 1 Additional Control Structures Chapter 9 2 New and Improved... Ways to branch Ways to write loops Understanding the break and continue statements.
STRUCTURED PROGRAMMING C++ Operators. Content 2  C++ operators  Assignment operators  Arithmetic operators  Increment and decrement operators  Decision.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Reminders: Have you filled out the questionnaire in Moodle? (3 left – as of last night). Office hours.
Week 3 - Friday.  What did we talk about last time?  Preprocessor directives  Other C features  sizeof, const  ASCII table  printf() format strings.
CHAPTER 4 CS 3370 – C++ Expressions. Operators Unary -, *, ++, -- higher precedence than binary operators most associate right-to-left Binary most associate.
Lecture 3.1 Operators and Expressions Structured Programming Instructor: Prof. K. T. Tsang 1.
 2006 Pearson Education, Inc. All rights reserved if…else Double-Selection Statement if – Performs action if condition true if…else – Performs.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
EGR 2261 Unit 11 Pointers and Dynamic Variables
LESSON 06.
CSE 220 – C Programming Expressions.
Expressions and Assignment Statements
Week 3 - Friday CS222.
Precedence and Associativity
JavaScript: Control Statements I
C++ Simple Data Types Simple types Integral Floating
Lecture 3 Expressions Richard Gesick.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
All the Operators 22-Nov-18.
Numerical Data Types.
Unary Operators ++ and --
Chapter 7 Additional Control Structures
All the Operators 4-Dec-18.
Chapter-3 Operators.
3 Control Statements:.
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Chap 7. Advanced Control Statements in Java
Using C++ Arithmetic Operators and Control Structures
OPERATORS in C Programming
HNDIT11034 More Operators.
OPERATORS in C Programming
Presentation transcript:

Additional C++ Operators ROBERT REAVES

Choosing a Looping Statement  Count-controlled loop, use for loop.  Event-controlled loop whose body should execute once, use do- while loop.  Event-controlled loop and nothing is known about the first execution, use while loop.  When in doubt, use a while loop.  Infinite loop, break statements sometimes help.

Additional C++ Operators  P. 323 – 324

Assignment Operators and Assignment Expressions  Assignment Expression is a C++ expression with a value and the side effect of storing the expression value into a memory location.  delta = 2 * 12;  is an expressions, so you can use it anywhere an expression is allowed.  thirdInt = (secondInt = (firstInt = 20) + 10) + 5;  Expression Statement is a statement formed by appending a semicolon to an expression.  23;  2 * (alpha + beta)

Increment and Decrement Operators  ++someInt is pre-incrementation  Incrementing occurs before use.  someInt++ is post-incrementation  Use before incrementing occurs.

Bitwise Operators  <<, left shift  >>, right shift  &, bitwise AND  |, bitwise OR  Used for manipulating individual bits within a memory cell.

Cast Operation  Cast operation comes in three forms:  intVar = int(floatVar);// Functional notation  intVar = (int)floatVar;// Prefix notation  intVar = static_cast (floatVar);// Keyword notation  Use explicit type cast to avoid confusing code with implicit type coercion.

Sizeof()  Unary operator that yields the size, in bytes, of its operand.  sizeof(long);  cout << sizeof(int) << endl;

?: Operator  Called the conditional operator, ternary (three-operand) operator.  Expression1? Expression2 : Expression3  if( a > b)  max = a;  else  max = b;  EQUIVLIENT TO:  max = (a > b) ? a : b;