More C expressions ANSI-C.

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Chapter 2: Basic Elements of C++
Introduction to C Programming
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
For(int i = 1; i
Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
Operator Overloading. C++ 2 Outline  General technique  Overloading of the assignment operator  Overloading the increment and decrement operators.
COMP1180 Review Date: 4 March, 2009 Time: 10:30am - 12:20pm Venue: –CS students -- FSC801C and FSC801D –IS and other students -- OEE1017 Remarks: – 1)
Chapter 2: Java Fundamentals Operators. Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 2 Content Group of Operators Arithmetic Operators Assignment.
Compound Operators 03/07/11. More Operators, First Section 4.4.
1 Shortcuts for Lazy Programmers! Topics Increment and Decrement Operators Assignment Operators.
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
1  Ex: Declare a variable to store user’s age: int age; Prompt the user to enter his/her age: printf (“ How old are you? “); Read / scan the entered value.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Shorthand operators.
Chapter 4: Basic C Operators
Simple Control Structures IF, IF-ELSE statements in C.
Looping II (for statement). CSCE 1062 Outline  for statement  Nested loops  Compound assignment operators  Increment and decrement operators.
Introduction to Programming Languages S1.3.1Bina © 1998 Liran & Ofir Introduction to Programming Languages Programming in C.
03 August 2004 NLP-AI Java Lecture No. 4 Operators & Decision Constructs Satish Dethe.
© 2006 Pearson Education 1 Obj: to use assignment operators HW: Prelab Exercises 2 Quiz 3.1 – 3.4 in two class days  Do Now: 1.Read p.144 – 145 (3.4 “more.
The Assignment operator tMyn1 The Assignment Operator The result of a calculation can be stored in a variable using the assignment operator =. Because.
By: Mr. Baha Hanene Chapter 6. LEARNING OUTCOMES This chapter will cover the learning outcome 02 i.e. 2.Use basic data-types and input / output in C programs.
1 10/3/05CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
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
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.
CHAPTER 2 PART #4 OPERATOR 1 st semester King Saud University College of Applied studies and Community Service Csc
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
Syntax(1). 2 Syntax  The syntax of a programming language is a precise description of all its grammatically correct programs.  Levels of syntax Lexical.
Side Effect Operators Changing the value of variables
Computing Fundamentals
for Repetition Structures
Syntax (1).
Abstract Syntax Trees Lecture 14 Mon, Feb 28, 2005.
Variable Declarations, Data types, Expressions
Variable Declarations, Data types, Expressions
Chapter 4 Top-Down Parsing Part-1 September 8, 2018
Arithmetic Operator Operation Example + addition x + y
Lecture 3: Introduction to Syntax (Cont’)
Compiler Design 4. Language Grammars
2008/10/27: Lecture 13 CMSC 104, Section 0101 John Y. Park
Increment and Decrement
Lecture 3 Expressions Richard Gesick.
Introduction to Programming
Example Problems for Exam#2 (covers chapters 5, 6, 7, 8, 9)
With Assignment Operator
C Operators, Operands, Expressions & Statements
Chapter-3 Operators.
Repetition Control Structure
Relational, Logical, and Equality Operators
VHDL Programming (08 Marks)
2008/10/27: Lecture 13 CMSC 104, Section 0101 John Y. Park
Expressions and Assignment Statements
Expressions and Assignment
Assignment Operators Topics Increment and Decrement Operators
Chapter 2: Java Fundamentals
Data Types and Expressions
PROGRAM FLOWCHART Iteration Statements.
Chap 7. Advanced Control Statements in Java
Assignment Operators Topics Increment and Decrement Operators
OPERATORS in C Programming
Assignment Operators Topics Increment and Decrement Operators
HNDIT11034 More Operators.
Assignment Operators Topics Increment and Decrement Operators
Data Types and Expressions
Assignment Operators Topics Increment and Decrement Operators
OPERATORS in C Programming
3.0 - Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
Data Types and Expressions
Presentation transcript:

More C expressions ANSI-C

Increment and decrement operators Expression Expression Value Effect i++ value of i before increment i is incremented ++i value of i after increment i is incremented Examples: int i = 0; int j; j = i++; /* j is 2 and i is 3 */ j = ++i; /* j is 4 and i is 4 */

Assigment Expression Assignment is an expression, thus it can appear anywhere an expression can appear. The value of an assigment expression is the same as the value of its right hand side. if ( x = (y + 10)) statement;

Conditional expression Syntax: expr1 ? exp2 : exp3 This is equivalent to write: if (expr1) exp2; else expr3; Example: y = (x>0) ? x = -x;

(and <<= >>= &= ^= |=, not covered) In general a op= b; Assignment Operators += -= *= %= (and <<= >>= &= ^= |=, not covered) In general a op= b; It’s (almost) equivalent to: a = a op (b); Example: int x = 5; int y = 10; x -= y + 3; x = x – (y + 3);