CS 161 Introduction to Programming and Problem Solving Chapter 12 C++ Statements Herbert G. Mayer, PSU Status 10/8/2014 Initial content copied verbatim.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

LECTURE 3: BASIC C OPERATORS. Objectives  In this chapter, you will learn about:  Arithmetic operators Unary operators Binary operators  Assignment.
C++ Statements represent the lowest-level building blocks of a program and it may be like:. A simple statement is a computation terminated by a semicolon.
Lecture 02 Data Types, Conversions if Statements METU Dept. of Computer Eng. Summer 2002 Ceng230 - Section 01 Introduction To C Programming by Ahmet Sacan.
1 Operators And Expressions. 2 Operators Arithmetic Operators Relational and Logical Operators Special Operators.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
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.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
Chapter 11-12, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3.
C++ for Engineers and Scientists Third Edition
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
Chapter 4: Basic C Operators
Chapter 2: Introducing Data Types and Operators.  Know Java’s primitive types  Use literals  Initialize variables  Know the scope rules of variables.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Operators Gabriel Hugh Elkaim Spring 2012.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
2440: 211 Interactive Web Programming Expressions & Operators.
CS 161 Introduction to Programming and Problem Solving Chapter Hello World Program in C++ And Lexical Rules Herbert G. Mayer, PSU Status 10/18/2014.
Basic Operators. What is an operator? using expression is equal to 9. Here, 4 and 5 are called operands and + is the operator Python language supports.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand.
C Programming Lecture 6 : Operators Lecture notes : courtesy of Ohio Supercomputing Center, and Prof. Woo and Prof. Chang.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
CSIS 113A Lecture 3 Conditional & Switch Glenn Stevenson CSIS 113A MSJC.
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.
CS 161 Introduction to Programming and Problem Solving Chapter 19 Single-Dimensional Arrays Herbert G. Mayer, PSU Status 10/8/2014 Initial content copied.
ECE 103 Engineering Programming Chapter 18 Iteration Herbert G. Mayer, PSU CS Status 7/19/2015 Initial content copied verbatim from ECE 103 material developed.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
ECE 103 Engineering Programming Chapter 36 C Storage Classes Herbert G. Mayer, PSU CS Status 8/4/2014 Initial content copied verbatim from ECE 103 material.
ECE 103 Engineering Programming Chapter 49 Structures Unions, Part 1 Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE.
C# Operator Overloading and Type Conversions C#.NET Software Development Version 1.0.
Chapter 4 Control Structures C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Principles of Programming Chapter 4: Basic C Operators  In this chapter, you will learn about:  Arithmetic operators  Unary operators  Binary operators.
CS 161 Introduction to Programming and Problem Solving Chapter 18 Control Flow Through C++ Program Herbert G. Mayer, PSU Status 10/8/2014 Initial content.
Operators & Expressions
ECE 103 Engineering Programming Chapter 31 C Scopes Herbert G. Mayer, PSU CS Status 8/1/2015 Initial content copied verbatim from ECE 103 material developed.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Java Statements –Java Expressions –Postfix Expressions –Prefix Expressions –Evaluating.
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.
CS 161 Introduction to Programming and Problem Solving Chapter 17 Nested Loops Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Reminders: Have you filled out the questionnaire in Moodle? (3 left – as of last night). Office hours.
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
ECE 103 Engineering Programming Chapter 30 C Functions Herbert G. Mayer, PSU CS Status 8/9/2014 Initial content copied verbatim from ECE 103 material developed.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2012 CMPE-013/L Operators Gabriel Hugh Elkaim Spring 2012.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Operators & Expressions
Operators And Expressions
Operators and Expressions
University of Central Florida COP 3330 Object Oriented Programming
University of Central Florida COP 3330 Object Oriented Programming
Precedence and Associativity
Java Programming: From Problem Analysis to Program Design, 4e
Introduction to C Programming
11/10/2018.
Operators and Expressions
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Introduction to C Programming
C Operators, Operands, Expressions & Statements
Associativity and Prescedence
Introduction to Programming – 4 Operators
ECE 103 Engineering Programming Chapter 19 Nested Loops
ECE 103 Engineering Programming Chapter 12 More C Statements
ECE 103 Engineering Programming Chapter 20 Change in Flow of Control
ECE 103 Engineering Programming Chapter 35 C Pointers, Part 1
Herbert G. Mayer, PSU CS Status 7/19/2015
Chapter 4: Expression and Operator
ECE 103 Engineering Programming Chapter 38 C Pointers, Part 2
C++ Programming Language Lecture 4 C++ Basics – Part II
Review of Previous Lesson
Presentation transcript:

CS 161 Introduction to Programming and Problem Solving Chapter 12 C++ Statements Herbert G. Mayer, PSU Status 10/8/2014 Initial content copied verbatim from ECE 103 material by prof. Phillip PSU

Syllabus Individual Statements Statement Bocks Examples List of C Operators

2 Individual C++ Statements A statement is a valid combination of keywords and expressions that forms a complete action Expressions consists of operands and combining operators; list of operators below Statements are executed in sequence to accomplish a specified task Individual statements are terminated by semicolon ; An additional semicolon by itself creates a null statement; null statements generate no code

3 A statement block (AKA a compound statement) is a sequence of 0 or more statements grouped together { // opening brace, marks the start of the block } // ending brace, marks the end of the block Syntax: { statement; : } There is no need for a semicolon after the ending brace.

4 Variables declared outside a block can be accessed from inside the block, unless overridden; they are said to be global to the inner scope Variables can be declared inside a block:  These variables have local scope  Inside the block, a local variable takes precedence over a variable having the same name from outside the block; i.e. a search for names progresses from inner toward outer scopes

5 #include /* All variables in same scope */ int main( void ) { // main int x, y; x = 2; y = 3 * x; printf( "A: %d %d\n", x, y ); x = 4; y = 3 * x; printf( "B: %d %d\n", x, y ); printf( "C: %d %d\n", x, y ); return 0; } //end main Output: A: 2 6 B: 4 12 C: 4 12 #include /* Scope depends on block */ int main (void) { // main int x, y; x = 2; y = 3 * x; printf( "A: %d %d\n", x, y ); { // a new block int x; x = 4; y = 3 * x; printf( "B: %d %d\n", x, y ); } //end of block printf( "C: %d %d\n", x, y ); return 0; } //end main Output: A: 2 6 B: 4 12 C: 2 12

6 #include /* Scope depends on block */ int main( void ) { // main int x = 1, y = 10; printf( "A: %d %d\n", x, y ); { // new block, level 2 int x = 3; printf("B: %d %d\n", x, y); x = 5; y = 20; printf("C: %d %d\n", x, y); { // new nested block, level 3 int x = 7; printf( "D: %d %d\n", x, y ); y = 30; printf( "E: %d %d\n", x, y ); } //end boxck level 3 printf( "F: %d %d\n", x, y ); } //end block level 2 printf( "G: %d %d\n", x, y ); return 0; } //end main A variable's scope determines its visibility or accessibility from other parts of a program.

7 #include /* Scope depends on block */ int main( void ) { // main int x = 1, y = 10; printf( "A: %d %d\n", x, y ); { // new block, level 2 int x = 3; printf("B: %d %d\n", x, y); x = 5; y = 20; printf("C: %d %d\n", x, y); { // new nested block, level 3 int x = 7; printf( "D: %d %d\n", x, y ); y = 30; printf( "E: %d %d\n", x, y ); } //end block level 3 printf( "F: %d %d\n", x, y ); } //end block level 2 printf( "G: %d %d\n", x, y ); return 0; } //end main A: 1 10B: 3 10C: 5 20F: 5 30E: 7 30D: 7 20G: 1 30

8 Table 1: C Operator Precedence Table in Decreasing Order LDescriptionOperatorAssociativityLDescriptionOperatorAssociativity 1 Function call ( ) left-to-right 5 Bitwise left shift << left-to-right Array subscript [ ] Bitwise right shift >> Struct member. 6 Less than < left-to-right Struct dereference -> Greater than > Increment (post) expr++ LT or equal to <= Decrement (post) expr-- GT or equal to >= 2 Indirection * right-to-left 7 Equal to == left-to-right Reference (addr) & Not equal to != Unary plus + 8Bitwise AND & left-to-right Unary minus - 9Bitwise XOR ^ left-to-right Logical negation ! 10Bitwise OR | left-to-right Bitwise NOT ~ 11Logical AND && left-to-right Increment (pre) ++expr 12Logical OR || left-to-right Decrement (pre) --expr 13Conditional ? : right-to-left Cast ( type ) 14Assignment = += -= *= /= %= >>= <<= &= ^= |= right-to-left Size in bytes sizeof 3 Multiplication * left-to-right 15Comma, left-to-right Division / Highest precedence is Level 1. Lowest precedence is Level 15. Modulo % 4 Addition + left-to-right Subtraction -