# Basic Assignment and Arithmetic Operators

Size: px
Start display at page:

Transcription

1 C Programming 1 Basic Assignment and Arithmetic Operators

2 C Programming 2 Assignment Operator = int count ; count = 10 ; The first line declares the variable count. In the second line an assignment operator (=) is used to store 10 in the location of count.

3 C Programming 3 In C language count = 10 is called an expression (with side effect) where = is called the assignment operator (not equality). Value of the expression is 10. The semicolon ; converts the expression to a statement.

4 C Programming 4 Next statement - count = 2*count + 5; In this statement the variable count is used on two sides of the assignment operator. There are two constants 2 and 5, and three operators = (assignment), (multiplication) and + (addition). count = 2*count + 5 is an expression (excluding the semicolon).

5 C Programming 5 The informal semantics (action, meaning) of the previous expression is the following: The content (r-value) of count is multiplied by 2, then 5 is added to the result ( is 25). The final value 25 is stored in the location (l-value) of count. The value of the expression is 25.

6 C Programming 6 int count; garbage count int count = 10 ; 10 count count = 2*count + 5; count 25

7 C Programming 7 Assignment from One Type to Another A float data can be assigned to an int variable, but there may be loss of precession. Similarly an int data can also be assigned to a variable of type float; but again there may be loss information. These processes are called type casting.

8 C Programming 8 7 int count e+09 float cgpa

9 C Programming 9 #include <stdio.h> int main() // temp1.c { int count = (int) 7.5 ; float cgpa = (float) ; printf("count: %d\n", count); printf("cgpa: %e\n", cgpa); return 0 ; }

10 C Programming 10 \$ cc -Wall temp.c \$./a.out count: 7 cgpa: e+09 Output

11 C Programming 11 Note Type casting is not a simple operation due to the difference in internal representations of int and float. In case of (int)7.5, the fractional part is removed and the value is 7 in 32-bit integer representation (2 s complement form). The value of (int)0.75 is zero (0).

12 C Programming 12 Note In the second case (float) converts the integer to IEEE 754 floating-point representation. In this format the number of bits available for storing the significant digits is 23, and all the digits of cannot be stored (2 23 = ). So there will be a loss of precision.

13 C Programming 13 Five Basic Arithmetic Operators +,,, /, % The first four operators have their usual meaning - addition, subtraction, multiplication and division. The last operator % extracts the remainder a. It may be called the mod operator. a a%b - the first operand a should be non-negative integer and the second operand b should be a positive integer.

14 C Programming 14 #include <stdio.h> int main() // temp2.c { printf("0%%10 = %d\n", 0%10); printf("4%%10 = %d\n", 4%10); printf("10%%4 = %d\n", 10%4); printf("-10%%4 = %d\n", -10%4); return 0 ; }

15 C Programming 15 \$ cc -Wall temp2.c \$./a.out 0%10 = 0 4%10 = 4 10%4 = 2-10%4 = -2 Output

16 C Programming 16 Operator Overloading The first four operators +,,,/ can be used for int, float and char data a. But the fifth operator cannot be used on float data. a The actual operations of addition, subtraction etc. on int and float data are very different due to the difference in their representations.

17 C Programming 17 Mixed Mode Operations Mixed mode operations among int, float and char data are permitted. If one operand is of type float and the other one is of type int, the int data will be converted to the closest float representation before performing the operation.

18 C Programming 18 #include <stdio.h> int main() // temp3.c { int n = 4 ; float a = 2.5 ; char c = a ; // ASCII value 97 printf("%d*%f = %f\n", n, a, n*a); printf("%d*%f+%c = %f\n",n,a,c,n*a+c); return 0 ; }

19 C Programming 19 Output \$ cc -Wall temp3.c \$./a.out 4* = * a =

20 C Programming 20 Computer Arithmetic! = 0.0 One should be careful about the division operation on int data.

21 C Programming 21 #include <stdio.h> int main() // temp4.c { printf("1/3*30.0=%f\n", 1/3*30.0); return 0 ; }

22 C Programming 22 \$ cc -Wall temp4.c \$./a.out 1/3*10.0= Output

23 C Programming 23 #include <stdio.h> int main() // temp4a.c { printf("10.0*1/3=%f\n", 10.0*1/3); printf("10.0*(1/3)=%f\n", 10.0*(1/3)); return 0 ; }

24 C Programming 24 \$ cc -Wall temp4a.c \$ a.out 10.0*1/3= *(1/3)= Output

25 C Programming 25 Computer Arithmetic! = Addition may give wrong result due to range overflow.

26 C Programming 26 #include <stdio.h> int main() // temp14.c { int n = ; printf("n+1: %d\n", n+1) ; return 0 ; }

27 C Programming 27 \$ cc -Wall temp14.c \$./a.out n+1: Output

28 C Programming 28 Computer Arithmetic! = 10 5 There will be loss of precession in floating point arithmetic.

29 C Programming 29 #include <stdio.h> int main() // temp8.c { float a = 1.0e-40, b = 1.0e+5, c; c = a+b ; printf("%e + %e = %e\n", a, b, c); if(b == a+b) printf("equal\n"); else printf("not Equal\n"); return 0 ; }

30 C Programming 30 Output \$ cc -Wall temp8.c \$ a.out e e+05 = e+05 Equal \$

31 C Programming 31 Precedence and Associativity All these five operators +,,,/,% are left-to-right associative.,/,% have same precedence and it is higher than +, which also have the same precedence.

32 C Programming 32 = is Right Associative int count = 10, n ; n = count = 2*count + 5 ; The variable n gets the updated value of count i.e. 25.

33 C Programming 33 Precedence of = The precedence of assignment operator(s) is lower than every other operator except the comma, operator.

34 C Programming 34 Computer Arithmetic! 1.3 float a = 1.3;

35 C Programming 35 #include <stdio.h> int main() // temp5.c { float a = 1.3 ; } if(a == 1.3) printf("equal\n") ; else printf("not equal\n") ; return 0 ;

36 C Programming 36 \$ cc -Wall temp5.c \$./a.out Not equal Output

37 C Programming 37 Error Division of int data by zero gives error at run time a. But the division of float or double data by zero does not generate any run time error. The result is inf b. a GCC error message is funny. b This value can be used.

38 C Programming 38 #include <stdio.h> int main() // temp9.c { int n = 10, m ; printf("enter an integer: "); scanf("%d", &m); printf("n/m: %d\n", n/m); return 0 ; }

39 C Programming 39 Output \$ cc -Wall temp9.c \$./a.out Enter an integer: 0 Floating point exception

40 C Programming 40 #include <stdio.h> #include <math.h> int main() // temp10.c { float n = 10.0, m, r ; printf("enter a number: "); scanf("%f", &m); printf("n/m: %f\n", r = n/m); printf("atan(%f) = %f\n", r, atan(r)); return 0 ; }

41 C Programming 41 Output \$ cc -Wall temp10.c -lm \$ a.out Enter a number: 0 n/m: inf atan(inf) =

42 C Programming 42 Integer Character If a char data is assigned to an int type variable, the ASCII value of the data is stored in the location. But if an int data (32-bit size) is assigned to a char type variable (8-bit size), the least significant 8-bits of the data are stored in the location.

43 C Programming 43 int count ; char grade ; 67 C count A grade 1345

44 C Programming 44 #include <stdio.h> int main() // temp6.c { int count = C ; char grade = 1345 ; printf("count: %d, grade: %c\n", count, grade) ; return 0 ; }

45 C Programming 45 Output \$ cc -Wall temp6.c temp6.c: In function main : temp6.c:5: warning: overflow in implicit constant conversion \$./a.out count: 67, grade: A

46 C Programming 46 Note The ASCII code for C is 67 and that is stored in the location for count. The internal representation of 1345 is The decimal value of the least significant byte (8-bit) is 65, the ASCII code for A.

47 C Programming 47 Pre and Post Increments int count = 10, total = 10 ; ++count ; total++ ;

48 C Programming 48 Both ++count and total++ are expressions with increment operators. The first one is pre-increment and the second one is post-increment. At the end of execution of the corresponding statements, the value of each location is 11. But the value of the expression ++count is 11 and that of the total++ is 10.

49 C Programming 49 Pre and Post Decrements int count = 10, total = 10 ; --count ; total-- ; Similarly we have pre and post decrement operators.

50 C Programming 50 More Assignment Operators int count = 10, total = 6 ; count += 5*total ; The new value of count is = 40. count += 5*total; is equivalent to count=count+5*total;.

51 C Programming 51 More Assignment Operators But count *= 5+total; is not same as count = count*5+total; In the first case the value is 10 (5+6) = 110. But in the second case it is = 56.

52 C Programming 52 #include <stdio.h> int main(){ // temp7a.c int count = 10, total = 6; } printf("first val: %d\n", count *= 5+total); count = 10; total = 6; printf("sec. val: %d\n", count = count*5+total); return 0;

53 C Programming 53 Unary + and The unary and + have their usual meaning with higher precedence than,/,%.

### Programming & Data Structure: CS Section - 1/A DO NOT POWER ON THE MACHINE

DS Tutorial: III (CS 11001): Section 1 Dept. of CS&Engg., IIT Kharagpur 1 Tutorial Programming & Data Structure: CS 11001 Section - 1/A DO NOT POWER ON THE MACHINE Department of Computer Science and Engineering

### Computer System and programming in C

1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

### IEEE 754 Floating-Point Format

C Programming 1 IEEE 754 Floating-Point Format C Programming 2 Floating-Point Decimal Number 123456. 10 1 = 12345.6 10 0 = 1234.56 10 1 = 123.456 10 2 = 12.3456 10 3 = 1.23456 10 4 (normalised) 0.12345

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

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

### Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

Day05 A Young W. Lim 2017-10-07 Sat Young W. Lim Day05 A 2017-10-07 Sat 1 / 14 Outline 1 Based on 2 Structured Programming (2) Conditions and Loops Conditional Statements Loop Statements Type Cast Young

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

### Introduction to C. Systems Programming Concepts

Introduction to C Systems Programming Concepts Introduction to C A simple C Program Variable Declarations printf ( ) Compiling and Running a C Program Sizeof Program #include What is True in C? if example

### These are reserved words of the C language. For example int, float, if, else, for, while etc.

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 a sequence of letters and digits, but must start with a letter.

### Informatics Ingeniería en Electrónica y Automática Industrial

Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical

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

### Lecture 3. More About C

Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

### Chapter 4: Basic C Operators

Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional

### Operators and Expressions:

Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

### 3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:

### Programming and Data Structures

Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()

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

### 1.3b Type Conversion

1.3b Type Conversion Type Conversion When we write expressions involved data that involves two different data types, such as multiplying an integer and floating point number, we need to perform a type

### Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

### IEEE 754 Floating-Point Format

PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 IEEE 754 Floating-Point Format PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 Floating-Point Decimal Number 123456. 10 1 = 12345.6 10 0 = 1234.56 10

### Operators and Expression. Dr Muhamad Zaini Yunos JKBR, FKMP

Operators and Expression Dr Muhamad Zaini Yunos JKBR, FKMP Arithmetic operators Unary operators Relational operators Logical operators Assignment operators Conditional operators Comma operators Operators

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

### MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

MA 511: Computer Programming Lecture 3: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11 Last

### Yacoub Sabatin Muntaser Abulafi Omar Qaraeen. Introduction

Introduction to Computer Engineering 0702111 2. Expressions Yacoub Sabatin Muntaser Abulafi Omar Qaraeen 1 Introduction A typical programming scenario: Read input data using scanf function, Perform some

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

### CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values

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

### Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how

### 2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a

### Data Types and Variables in C language

Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators

### Expressions and Statementst t. Assignment Operator. C Programming Lecture 6 : Operators. Expression

Expressions and Statementst t Expression C Programming Lecture 6 : Operators Combination of constants,variables,operators, operators and function calls a+b 3.0*x 9.66553 tan(angle) Statement An expression

### COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

COSC 243 Data Representation 3 Lecture 3 - Data Representation 3 1 Data Representation Test Material Lectures 1, 2, and 3 Tutorials 1b, 2a, and 2b During Tutorial a Next Week 12 th and 13 th March If you

### ISA 563 : Fundamentals of Systems Programming

ISA 563 : Fundamentals of Systems Programming Variables, Primitive Types, Operators, and Expressions September 4 th 2008 Outline Define Expressions Discuss how to represent data in a program variable name

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

### C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

C-Programming CSC209: Software Tools and Systems Programming Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Adapted from Dan Zingaro s 2015 slides. Week 2.0 1 / 19 What

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

### C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }

C Program Output #include main () { printf ( Hi everyone\n ); Hi everyone #include main () { printf ( Hi everyone\n ); #include and main are Keywords (or Reserved Words) Reserved Words

### The C language. Introductory course #1

The C language Introductory course #1 History of C Born at AT&T Bell Laboratory of USA in 1972. Written by Dennis Ritchie C language was created for designing the UNIX operating system Quickly adopted

### C Programming

204216 -- C Programming Chapter 3 Processing and Interactive Input Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives Assignment Mathematical Library

### Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

### Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

### Data types, variables, constants

Data types, variables, constants Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic in C 2.6 Decision

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

### CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

### MA 511: Computer Programming Lecture 2: Partha Sarathi Mandal

MA 511: Computer Programming Lecture 2: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11 Largest

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

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

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

### 2. Numbers In, Numbers Out

COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break

### Programming in C++ 5. Integral data types

Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long

### Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Lesson #3 Variables, Operators, and Expressions Variables We already know the three main types of variables in C: int, char, and double. There is also the float type which is similar to double with only

### Basics of Programming

Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the

### Data Type Fall 2014 Jinkyu Jeong

Data Type Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Syntax Rules Recap. keywords break double if sizeof void case else int static... Identifiers not#me scanf 123th printf _id so_am_i gedd007 Constants

### Structured programming

Exercises 2 Version 1.0, 22 September, 2016 Table of Contents 1. Simple C program structure................................................... 1 2. C Functions..................................................................

### 2. Numbers In, Numbers Out

REGZ9280: Global Education Short Course - Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. REGZ9280 14s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write

### Chapter 3. Section 3.10 Type of Expressions and Automatic Conversion. CS 50 Hathairat Rattanasook

Chapter 3 Section 3.10 Type of Expressions and Automatic Conversion CS 50 Hathairat Rattanasook Types of Expressions and Automatic Conversions In C, every expression has an associated type. Operators and

### Chapter 2: Using Data

Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

### Structured programming. Exercises 3

Exercises 3 Table of Contents 1. Reminder from lectures...................................................... 1 1.1. Relational operators..................................................... 1 1.2. Logical

### Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

### More Programming Constructs -- Introduction

More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

### Unit-2 (Operators) ANAND KR.SRIVASTAVA

Unit-2 (Operators) ANAND KR.SRIVASTAVA 1 Operators in C ( use of operators in C ) Operators are the symbol, to perform some operation ( calculation, manipulation). Set of Operations are used in completion

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

### Add Subtract Multiply Divide

ARITHMETIC OPERATORS if AND if/else AND while LOOP Order of Operation (Precedence Part 1) Copyright 2014 Dan McElroy Add Subtract Multiply Divide + Add - Subtract * Multiply / Divide = gives the quotient

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

### Operators and expressions. (precedence and associability of operators, type conversions).

Programming I Laboratory - lesson 0 Operators and expressions (precedence and associability of operators, type conversions). An expression is any computation which yields a value. When discussing expressions,

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

### Operators in C. Staff Incharge: S.Sasirekha

Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C

### 3. Java - Language Constructs I

Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

### Arithmetic type issues

Arithmetic type issues Type combination and promotion ( a 32) = 97 32 = 65 = A Smaller type (char) is promoted to be the same size as the larger type (int) Determined at compile time - based purely on

### Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

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

### CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

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

### Declaration and Memory

Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier

### COMP2611: Computer Organization. Data Representation

COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How

### C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

### CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

CSE101-lec#12 Designing Structured Programs Introduction to Functions Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Designing structured programs in C: Counter-controlled repetition

### Chapter 3 Structure of a C Program

Chapter 3 Structure of a C Program Objectives To be able to list and describe the six expression categories To understand the rules of precedence and associativity in evaluating expressions To understand

### Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and

### Chapter 3 Structured Program Development in C Part II

Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 3.7 The while Iteration Statement An iteration statement (also called

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

### Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.

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

### Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

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

### CIS133J. Working with Numbers in Java

CIS133J Working with Numbers in Java Contents: Using variables with integral numbers Using variables with floating point numbers How to declare integral variables How to declare floating point 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 of Programming Session 7

Fundamentals of Programming Session 7 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2014 These slides have been created using Deitel s slides Sharif University of Technology Outlines

### Part I Part 1 Expressions

Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague

### Writing Program in C Expressions and Control Structures (Selection Statements and Loops)

Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague

### Engineering Computing I

Engineering Computing I Types, Operators, and Expressions Types Operators Expressions 2 1 2.1 Variable Names Names are made up of letters and digits The first character must be a letter The underscore

### COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

### C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

### CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

### Operators and Expressions

Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

### Chapter 2: Using Data

Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

### CHAPTER 3 Expressions, Functions, Output

CHAPTER 3 Expressions, Functions, Output More Data Types: Integral Number Types short, long, int (all represent integer values with no fractional part). Computer Representation of integer numbers - Number

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