Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Similar documents
Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

JAVA OPERATORS GENERAL

Unit 3. Operators. School of Science and Technology INTRODUCTION

A flow chart is a graphical or symbolic representation of a process.

Operators in C. Staff Incharge: S.Sasirekha

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

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

Operators. Java operators are classified into three categories:

Unit-2 (Operators) ANAND KR.SRIVASTAVA

SECTION II: LANGUAGE BASICS

Department of Computer Science

Operators in java Operator operands.

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Prof. Navrati Saxena TA: Rochak Sachan

Operators and Expressions:

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following g roups:

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

Expression and Operator

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

Chapter 3: Operators, Expressions and Type Conversion

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

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

CT 229. Java Syntax 26/09/2006 CT229

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

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

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Data Types and Variables in C language

Expressions and Precedence. Last updated 12/10/18

Operators & Expressions

Prepared by: Shraddha Modi

UNIT- 3 Introduction to C++

UNIT 3 OPERATORS. [Marks- 12]

DEPARTMENT OF MATHS, MJ COLLEGE

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

Fundamentals of Programming

QUIZ: What value is stored in a after this

Arithmetic Operators. Portability: Printing Numbers

Information Science 1

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

Computers Programming Course 6. Iulian Năstac

Computer System and programming in C

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Variables and Operators 2/20/01 Lecture #

C expressions. (Reek, Ch. 5) 1 CS 3090: Safety Critical Programming in C

Lecture 3. More About C

CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section :

Programming in C++ 5. Integral data types

The Java language has a wide variety of modifiers, including the following:

Fundamental of Programming (C)

Perl: Arithmetic, Operator Precedence and other operators. Perl has five basic kinds of arithmetic:

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

Fundamentals of Programming CS-110. Lecture 3

CSC 1214: Object-Oriented Programming

Chapter 4. Operations on Data

CS313D: ADVANCED PROGRAMMING LANGUAGE

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

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

ME 461 C review Session Fall 2009 S. Keres

.Net Technologies. Components of.net Framework

Constants and Variables

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

Basics of Programming

Binary Representations and Arithmetic

LECTURE 3 C++ Basics Part 2

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

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Operators. Lecture 3 COP 3014 Spring January 16, 2018

CHAPTER 3 BASIC INSTRUCTION OF C++

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

More Programming Constructs -- Introduction

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

Programming for Engineers: Operators, Expressions, and Statem

Part I Part 1 Expressions

ISA 563 : Fundamentals of Systems Programming

Chapter 7. Expressions and Assignment Statements ISBN

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Engineering Computing I

9/2/2016. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

1/31/2017. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types

Operators and Expressions

Operators and Type Conversion. By Avani M. Sakhapara Assistant Professor, IT Dept, KJSCE

Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

Java Basic Programming Constructs

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Chapter 7. Expressions and Assignment Statements

Expressions & Assignment Statements

Chapter 12 Variables and Operators

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

BCA-105 C Language What is C? History of C

Reserved Words and Identifiers

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

Lecture 3 Tao Wang 1

Transcription:

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 a single operand Binary requires two operands Ternary requires three operands Following are the types of operators: Arithmetic Relational Logical Bitwise Assignment Conditional (ternary) Increment/Decrement Special

Types of operators Types of operators Arithmetic operators (binary) Assignment operators (binary) Relational operators (binary) Logical operators (binary) Bitwise operators (binary) Conditional operators (ternary) Increment/Decrement (unary) operators Special operators sizeof( ) Description These are used to perform mathematical calculations like addition, subtraction, multiplication, division and modulus. These are used to assign the values for the variables in programs. These operators are used to compare the value of two variables. These operators are used to perform logical operations on the given two variables. These operators are used to perform bit operations on given two variables. Conditional operators return one value if condition is true and returns another value is condition is false. These operators are used to either increase or decrease the value of the variable by one.

Arithmetic Operators Operator Description Example (A is 10, B is 20) + Adds two operands A + B will give 30 - Subtracts second operand from the first A B will give -10 * Multiplies both operands A * B will give 200 / Divides numerator by de-numerator B/A will give 2 and A/B will give 0.5(if float) and 0(if int) % Modulus Operator and remainder of after an integer division General form is operand1 operator operand2 B % A will give 0 and A % B will give 10

Assignment Operators Operator Description Example = Simple assignment operator, Assigns values from right side operands to left side operand += Compound assignment operator, Add and assignment operator. It adds right operand to the left operand and assign the result to left operand -= Compound assignment operator, Subtract and assignment operator. It subtract right operand from the left operand and assign the result to left operand, others would be *=, /=, %= C = A + B will assign value of A + B into C C += A is equivalent to C = C + A C -= A is equivalent to C = C - A <<= Left shift and assignment operator C <<= 2 is same as C = C << 2 >>= Right shift and assignment operator C >>= 2 is same as C = C >> 2 &= Bitwise and assignment operator, others would be ^=, = C &= 2 is same as C = C & 2 General form is v op= exp where v is a variable and op is a binary arithmetic operator. This statement is equivalent to v = v op(exp)

Relational Operators Operator Description Example (A is 10, B is 20) == Checks if the values of two operands are equal or not, if yes then condition becomes true.!= Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. A == B will give 0 A!= B will give 1 A > B will give 0 A < B will give 1 A >= B will give 0 A <= B will give 1 General form is operand1 relational-operator operand2 takes a value of 1(int) if the relationship is true and 0(int) if relationship is false.

Logical Operators Operator Description Example (A is 10, B is 20) && Called Logical AND operator. If both the operands are non-zero, then condition becomes true. Called Logical OR Operator. If any of the two operands is nonzero, then condition becomes true.! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. (A>=10) && (B>15) will give 1 (A>10) && (B>15) will give 0 (A>10) (B>15) will give 1 (A>10) will give 0!(A>10) will give 1 General form is operand1 logical-operator operand2 takes a value of 1(int) if the relationship is true and 0(int) if relationship is false. expr1 && expr2 has a value 1 if expr1 and expr2 both are nonzero. expr1 expr2 has a value 1 if expr1 and expr2, any one of them is nonzero.!expr1 has a value 1 if expr1 is zero else 0.

Bitwise Operators Operator Description Example (A is 60, B is 13) & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) = 12 (0000 1100) Binary OR Operator copies a bit if it exists in either operand. (A B) = 61 (0011 1101) ~ Binary NOT Operator is unary and has the effect of 'flipping' bits. (~A) = -61 (1100 0011 in 2 s complement form) ^ Binary XOR Operator copies the bit if it is set in one operand but not both. << Binary Left Shift Operator. The left operand s value is moved left by the number of bits specified by the right operand. >> Binary Right Shift Operator. The left operand s value is moved right by the number of bits specified by the right operand. (A ^ B) = 49 (0011 0001) A << 2 will give 240 which is 1111 0000 A >> 2 will give 15 which is 0000 1111

Increment/Decrement Operators Increment operators are used to increase the value of the variable by one and decrement operators are used to decrease the value of the variable by one in C programs. Syntax: Increment operator: ++var_name; (or) var_name++; Decrement operator: -var_name; (or) var_name -;

Conditional Operators A ternary operator pair?: is available to construct conditional expression of the form Exp1? Exp2 : Exp3 where Exp1, Exp2 and Exp3 are expressions. The operator?: works as follows: Exp1 is evaluated first. If it is nonzero (true), then the expression Exp2 is evaluated and becomes the value of the expression. If Exp1 is false, Exp3 is evaluated and its value becomes the value of the expression. Syntax (Condition? true_value: false_value); E.g. a = 10; b = 15; x = (a > b)? a : b 10

Special Operators To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes. int a; sizeof(a) 2 bytes (in 32 bit machine) and 4 bytes (in 64 bit machine) float b; sizeof(b) 4 bytes double c; sizeof(c) 8 bytes char d; sizeof(d) 1 byte 11

Precedence and Associativity Precedence and Associativity are two characteristics of operators that determine the evaluation order of subexpressions in absence of brackets. Please check document attached in blog for this topic. Some points: All operators with same precedence have same associativity This is necessary, otherwise there won t be any way for compiler to decide evaluation order of expressions which have two operators of same precedence and different associativity. For example + and have same associativity. Associativity is only used when there are two or more operators of same precedence.

ANY QUESTIONS???