0% found this document useful (0 votes)
52 views

Lect09 LogBitOperator PDF

The document discusses operator precedence and rules for evaluating expressions in C programming. It covers unary operators like - and +, binary operators like + and -, and operator precedence levels. Precedence levels are explained with multiplication and division having higher precedence than addition and subtraction. Rules for evaluating expressions including parentheses, operator precedence, and associativity are also outlined.

Uploaded by

Divyansh Pandey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Lect09 LogBitOperator PDF

The document discusses operator precedence and rules for evaluating expressions in C programming. It covers unary operators like - and +, binary operators like + and -, and operator precedence levels. Precedence levels are explained with multiplication and division having higher precedence than addition and subtraction. Rules for evaluating expressions including parentheses, operator precedence, and associativity are also outlined.

Uploaded by

Divyansh Pandey
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

C Fundamentals

Dr. Odelu Vanga

Department of Computer Science and Information Systems


Birla Institute of Technology and Science Pilani
Hyderabad Campus
[email protected]

February 03, 2020

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 1 / 22


Today’s Topics

Expression Evaluations
Precedence of Operator
Logical Operators
Relational Operators
Bitwise operators
Comma (operator, separator)
Some Interesting Evaluations

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 2 / 22


Expressions with Multiple Operators

Unary operators (example, plus (+) and negative (-)):


x = −y;
z = +x ∗ y;

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 3 / 22


Expressions with Multiple Operators

Unary operators (example, plus (+) and negative (-)):


x = −y;
z = +x ∗ y;
Binary operators (requires two operands):
x = y + z;
z = y − x;

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 3 / 22


Expressions with Multiple Operators

Unary operators (example, plus (+) and negative (-)):


x = −y;
z = +x ∗ y;
Binary operators (requires two operands):
x = y + z;
z = y − x;
For example, in the expression x + y/z
Is + performed before / ?
Is + performed after / ?

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 3 / 22


Expressions with Multiple Operators

Unary operators (example, plus (+) and negative (-)):


x = −y;
z = +x ∗ y;
Binary operators (requires two operands):
x = y + z;
z = y − x;
For example, in the expression x + y/z
Is + performed before / ?
Is + performed after / ?
Is the expression x/y ∗ z evaluated as (x/y) ∗ z or as x/(y ∗ z)?

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 3 / 22


Rules for Evaluating Expressions

1.) Parentheses rule: All expressions in parentheses must be evaluated


separately. Nested parenthesized expressions must be evaluated from
the inside out, with the innermost expression evaluated first.

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 4 / 22


Rules for Evaluating Expressions

1.) Parentheses rule: All expressions in parentheses must be evaluated


separately. Nested parenthesized expressions must be evaluated from
the inside out, with the innermost expression evaluated first.
2.) Operator precedence rule: Operators in the same expression are
evaluated in the following order:
unary +, − first
∗, /, % next
binary +, − last

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 4 / 22


Rules for Evaluating Expressions

1.) Parentheses rule: All expressions in parentheses must be evaluated


separately. Nested parenthesized expressions must be evaluated from
the inside out, with the innermost expression evaluated first.
2.) Operator precedence rule: Operators in the same expression are
evaluated in the following order:
unary +, − first
∗, /, % next
binary +, − last
3). Associativity rule: Unary operators in the same subexpression and at
the same precedence level (such as + and −) are evaluated right to left
(right associativity).

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 4 / 22


Rules for Evaluating Expressions

1.) Parentheses rule: All expressions in parentheses must be evaluated


separately. Nested parenthesized expressions must be evaluated from
the inside out, with the innermost expression evaluated first.
2.) Operator precedence rule: Operators in the same expression are
evaluated in the following order:
unary +, − first
∗, /, % next
binary +, − last
3). Associativity rule: Unary operators in the same subexpression and at
the same precedence level (such as + and −) are evaluated right to left
(right associativity).
Binary operators in the same subexpression and at the same
precedence level (such as + and −) are evaluated left to right (left
associativity ).

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 4 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 −, ++, −−, !, ∼ R-L
3 ∗, /, % L-R
Operator Precedence
4 +, − L-R (1 + 2) ∗ 3
5 <<, >> L-R
1 + 2 ∗ 3 (* first)
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 5 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 −, ++, −−, !, ∼ R-L
3 ∗, /, % L-R
Operator Precedence
4 +, − L-R (1 + 2) ∗ 3
5 <<, >> L-R
1 + 2 ∗ 3 (* first)
6 <, <=, >, >= L-R
7 ==, ! = L-R Operator Associativity
8 & (bitwise AND) L-R 2 ∗ 6/3%4 (L-R)
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R 2 ∗ 6/(3%4)
11 && (Logical AND) L-R Change Precedence
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 5 / 22


Expression Evaluation
Evaluation for z − (a + b/2) + w ∗ −y using Evaluation Tree

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 6 / 22


Expression Evaluation
Evaluation for z − (a + b/2) + w ∗ −y using Evaluation Tree

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 6 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L Unary operators (R-L)
3 ∗, /, % L-R
4 +, − L-R Inc/Decrement Operators (R-L)
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 7 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R Unary operators (R-L)
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R ! (Not operator)
4 +, − L-R !3 is 0
5 <<, >> L-R !0 is 1
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 8 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R Unary operators (R-L)
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R ! (Not operator)
4 +, − L-R !3 is 0
5 <<, >> L-R !0 is 1
6 <, <=, >, >= L-R 1s (∼) and 2s (−)
7 ==, ! = L-R
complement
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R ∼ 3 is −4
10 | (bitwise OR) L-R −5 is −5
11 && (Logical AND) L-R
12 || (Logical OR) L-R
Number representation is in 2s
13 ? : (Conditional Op.) R-L complement
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 8 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R Shift Operators (L-R)
4 +, − L-R
5 <<, >> L-R 3 >> 1 is ? (right shift)
6 <, <=, >, >= L-R 3 << 1 is ? (left shift)
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 9 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R Shift Operators (L-R)
4 +, − L-R
5 <<, >> L-R 3 >> 1 is ? (right shift)
6 <, <=, >, >= L-R 3 << 1 is ? (left shift)
7 ==, ! = L-R
8 & (bitwise AND) L-R 310 = (11)2
9 ˆ (bitwise XOR) L-R
3 >> 1 = 11 >> 1
10 | (bitwise OR) L-R
11 && (Logical AND) L-R = (01)2 = 110
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 9 / 22


Operators and Precedence

Suppose a = 2, b=2, and c=4


Prec. Operator Assoc
1 () L-R Relational and Logical
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R !(a! = b) equals to 1
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 10 / 22


Operators and Precedence

Suppose a = 2, b=2, and c=4


Prec. Operator Assoc
1 () L-R Relational and Logical
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R !(a! = b) equals to 1
4 +, − L-R !(a == b) equals to 0
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 10 / 22


Operators and Precedence

Suppose a = 2, b=2, and c=4


Prec. Operator Assoc
1 () L-R Relational and Logical
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R !(a! = b) equals to 1
4 +, − L-R !(a == b) equals to 0
5 <<, >> L-R
6 <, <=, >, >= L-R (a == b)&&(c > b) equals to 1
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 10 / 22


Operators and Precedence

Suppose a = 2, b=2, and c=4


Prec. Operator Assoc
1 () L-R Relational and Logical
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R !(a! = b) equals to 1
4 +, − L-R !(a == b) equals to 0
5 <<, >> L-R
6 <, <=, >, >= L-R (a == b)&&(c > b) equals to 1
7 ==, ! = L-R (a == b)&&(c < b) equals to 0
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 10 / 22


Operators and Precedence

Suppose a = 2, b=2, and c=4


Prec. Operator Assoc
1 () L-R Relational and Logical
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R !(a! = b) equals to 1
4 +, − L-R !(a == b) equals to 0
5 <<, >> L-R
6 <, <=, >, >= L-R (a == b)&&(c > b) equals to 1
7 ==, ! = L-R (a == b)&&(c < b) equals to 0
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R (a == b)||(c < b) equals to 1
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 10 / 22


Operators and Precedence

Suppose a = 2, b=2, and c=4


Prec. Operator Assoc
1 () L-R Relational and Logical
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R !(a! = b) equals to 1
4 +, − L-R !(a == b) equals to 0
5 <<, >> L-R
6 <, <=, >, >= L-R (a == b)&&(c > b) equals to 1
7 ==, ! = L-R (a == b)&&(c < b) equals to 0
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R (a == b)||(c < b) equals to 1
10 | (bitwise OR) L-R
(a! = b)||(c < b) equals to 0
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L Relational Ops. returns T /F .
14 = (Assignment) R-L T : non-zero and F : zero
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 10 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 11 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ?
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 11 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ?a=2, b=5
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 11 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ?a=2, b=5
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 3, b = 2, output ?
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 11 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ?a=2, b=5
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 3, b = 2, output ? a=3, b=2
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 11 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ?a=2, b=5
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 3, b = 2, output ? a=3, b=2
9 ˆ (bitwise XOR) L-R
a = 2, b = 0, output ?
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 11 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ?a=2, b=5
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 3, b = 2, output ? a=3, b=2
9 ˆ (bitwise XOR) L-R
a = 2, b = 0, output ?a=2, b=5
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 11 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ?a=2, b=5
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 3, b = 2, output ? a=3, b=2
9 ˆ (bitwise XOR) L-R
a = 2, b = 0, output ?a=2, b=5
10 | (bitwise OR) L-R
11 && (Logical AND) L-R Note: (a==2) false, then it will not
12 || (Logical OR) L-R execute second one.
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 11 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ?a=2, b=5
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 3, b = 2, output ? a=3, b=2
9 ˆ (bitwise XOR) L-R
a = 2, b = 0, output ?a=2, b=5
10 | (bitwise OR) L-R
11 && (Logical AND) L-R Note: (a==2) false, then it will not
12 || (Logical OR) L-R execute second one.
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

How can you evaluate (a == 2)||(b = 5) ? for the above inputs.


Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 11 / 22
Operators and Precedence

Example
Prec. Operator Assoc if(a == 2&&b = 5)
1 () L-R print(a, b)
2 ++, −−, !, ∼, − R-L else
3 ∗, /, % L-R print(a, b)
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 12 / 22


Operators and Precedence

Example
Prec. Operator Assoc if(a == 2&&b = 5)
1 () L-R print(a, b)
2 ++, −−, !, ∼, − R-L else
3 ∗, /, % L-R print(a, b)
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R Example
7 ==, ! = L-R if(a = 2&&b == 5)
8 & (bitwise AND) L-R print(a, b)
9 ˆ (bitwise XOR) L-R else
10 | (bitwise OR) L-R
print(a, b)
11 && (Logical AND) L-R
12 || (Logical OR) L-R Evaluate for the inputs:
13 ? : (Conditional Op.) R-L a = 2, b = 3, output ?
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 12 / 22


Operators and Precedence

Example
Prec. Operator Assoc if(a == 2&&b = 5)
1 () L-R print(a, b)
2 ++, −−, !, ∼, − R-L else
3 ∗, /, % L-R print(a, b)
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R Example
7 ==, ! = L-R if(a = 2&&b == 5)
8 & (bitwise AND) L-R print(a, b)
9 ˆ (bitwise XOR) L-R else
10 | (bitwise OR) L-R
print(a, b)
11 && (Logical AND) L-R
12 || (Logical OR) L-R Evaluate for the inputs:
13 ? : (Conditional Op.) R-L a = 2, b = 3, output ? a=0, b=3
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 12 / 22


Operators and Precedence

Example
Prec. Operator Assoc if(a == 2&&b = 5)
1 () L-R print(a, b)
2 ++, −−, !, ∼, − R-L else
3 ∗, /, % L-R print(a, b)
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R Example
7 ==, ! = L-R if(a = 2&&b == 5)
8 & (bitwise AND) L-R print(a, b)
9 ˆ (bitwise XOR) L-R else
10 | (bitwise OR) L-R
print(a, b)
11 && (Logical AND) L-R
12 || (Logical OR) L-R Evaluate for the inputs:
13 ? : (Conditional Op.) R-L a = 2, b = 3, output ? a=0, b=3
14 = (Assignment) R-L a = 3, b = 2, output ?
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 12 / 22


Operators and Precedence

Example
Prec. Operator Assoc if(a == 2&&b = 5)
1 () L-R print(a, b)
2 ++, −−, !, ∼, − R-L else
3 ∗, /, % L-R print(a, b)
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R Example
7 ==, ! = L-R if(a = 2&&b == 5)
8 & (bitwise AND) L-R print(a, b)
9 ˆ (bitwise XOR) L-R else
10 | (bitwise OR) L-R
print(a, b)
11 && (Logical AND) L-R
12 || (Logical OR) L-R Evaluate for the inputs:
13 ? : (Conditional Op.) R-L a = 2, b = 3, output ? a=0, b=3
14 = (Assignment) R-L a = 3, b = 2, output ? a=0, b=2
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 12 / 22


Operators and Precedence

Example
Prec. Operator Assoc if(a == 2&&b = 5)
1 () L-R print(a, b)
2 ++, −−, !, ∼, − R-L else
3 ∗, /, % L-R print(a, b)
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R Example
7 ==, ! = L-R if(a = 2&&b == 5)
8 & (bitwise AND) L-R print(a, b)
9 ˆ (bitwise XOR) L-R else
10 | (bitwise OR) L-R
print(a, b)
11 && (Logical AND) L-R
12 || (Logical OR) L-R Evaluate for the inputs:
13 ? : (Conditional Op.) R-L a = 2, b = 3, output ? a=0, b=3
14 = (Assignment) R-L a = 3, b = 2, output ? a=0, b=2
15 , (Comma) L-R a = 0, b = 5, output ?

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 12 / 22


Operators and Precedence

Example
Prec. Operator Assoc if(a == 2&&b = 5)
1 () L-R print(a, b)
2 ++, −−, !, ∼, − R-L else
3 ∗, /, % L-R print(a, b)
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R Example
7 ==, ! = L-R if(a = 2&&b == 5)
8 & (bitwise AND) L-R print(a, b)
9 ˆ (bitwise XOR) L-R else
10 | (bitwise OR) L-R
print(a, b)
11 && (Logical AND) L-R
12 || (Logical OR) L-R Evaluate for the inputs:
13 ? : (Conditional Op.) R-L a = 2, b = 3, output ? a=0, b=3
14 = (Assignment) R-L a = 3, b = 2, output ? a=0, b=2
15 , (Comma) L-R a = 0, b = 5, output ?a=1, b=5

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 12 / 22


Operators and Precedence

Bitwise Operators
Prec. Operator Assoc
1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R Example
9 ˆ (bitwise XOR) L-R OR AND XOR
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
2 = 10 2 = 10 2 = 10
12 || (Logical OR) L-R 3 = 11 3 = 11 3 = 11
13 ? : (Conditional Op.) R-L ———– ———– ———–
14 = (Assignment) R-L 3 = 11 2 = 10 1 = 01
15 , (Comma) L-R ———- ———- ———-

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 13 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ?
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 14 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 0
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 14 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 0
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ?
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 14 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 0
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 4
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 14 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 0
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 4
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L a = 4, b = 5, v = 7, u = 11,
14 = (Assignment) R-L output ?
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 14 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 0
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 4
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L a = 4, b = 5, v = 7, u = 11,
14 = (Assignment) R-L output ? 0
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 14 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ?
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 15 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 15 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ?
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 15 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 7
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 15 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 7
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L a = 4, b = 5, v = 7, u = 11,
14 = (Assignment) R-L output ?
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 15 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 7
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L a = 4, b = 5, v = 7, u = 11,
14 = (Assignment) R-L output ? 7
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 15 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 7
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L a = 4, b = 5, v = 7, u = 11,
14 = (Assignment) R-L output ? 7
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 15 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ?
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 16 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 16 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ?
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 16 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 8
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 16 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 8
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L a = 4, b = 5, v = 7, u = 11,
14 = (Assignment) R-L output ?
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 16 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 1
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 8
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L a = 4, b = 5, v = 7, u = 11,
14 = (Assignment) R-L output ? 8
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 16 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ?
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 17 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 15
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 17 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 15
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ?
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 17 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 15
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 23
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 17 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 15
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 23
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L a = 4, b = 5, v = 7, u = 11,
14 = (Assignment) R-L output ?
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 17 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R a = 2, b = 3, v = 0, u = 1,
9 ˆ (bitwise XOR) L-R output ? 15
10 | (bitwise OR) L-R a = 11, b = 7, v = 5, u = 4,
11 && (Logical AND) L-R output ? 23
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L a = 4, b = 5, v = 7, u = 11,
14 = (Assignment) R-L output ? 31
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 17 / 22


Operators and Precedence

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 18 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ?
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 19 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ? 3
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 19 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ? 3
7 ==, ! = L-R a = 11, b = 7, output ?
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 19 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ? 3
7 ==, ! = L-R a = 11, b = 7, output ? 3
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 19 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ?
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 20 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ? 4
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 20 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ? 4
7 ==, ! = L-R
a = 11, b = 7, output ?
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 20 / 22


Operators and Precedence

Prec. Operator Assoc


1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R a = 2, b = 3, output ? 4
7 ==, ! = L-R
a = 11, b = 7, output ? 13
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 20 / 22


Operators and Precedence

Conditional Operators (R-L)


Prec. Operator Assoc (x > y)?printf (“x“) : printf (“y “)
1 () L-R
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 21 / 22


Operators and Precedence

Conditional Operators (R-L)


Prec. Operator Assoc (x > y)?printf (“x“) : printf (“y “)
1 () L-R x = 2, y = 3, then output ?
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R x = 5, y = 3, then output ?
4 +, − L-R
5 <<, >> L-R
6 <, <=, >, >= L-R
7 ==, ! = L-R
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R
10 | (bitwise OR) L-R
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 21 / 22


Operators and Precedence

Conditional Operators (R-L)


Prec. Operator Assoc (x > y)?printf (“x“) : printf (“y “)
1 () L-R x = 2, y = 3, then output ?
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R x = 5, y = 3, then output ?
4 +, − L-R
5 <<, >> L-R Same as
6 <, <=, >, >= L-R if(x > y)
7 ==, ! = L-R printf (“x“);
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R else
10 | (bitwise OR) L-R printf (“y“);
11 && (Logical AND) L-R
12 || (Logical OR) L-R
13 ? : (Conditional Op.) R-L
14 = (Assignment) R-L
15 , (Comma) L-R

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 21 / 22


Operators and Precedence

Conditional Operators (R-L)


Prec. Operator Assoc (x > y)?printf (“x“) : printf (“y “)
1 () L-R x = 2, y = 3, then output ?
2 ++, −−, !, ∼, − R-L
3 ∗, /, % L-R x = 5, y = 3, then output ?
4 +, − L-R
5 <<, >> L-R Same as
6 <, <=, >, >= L-R if(x > y)
7 ==, ! = L-R printf (“x“);
8 & (bitwise AND) L-R
9 ˆ (bitwise XOR) L-R else
10 | (bitwise OR) L-R printf (“y“);
11 && (Logical AND) L-R
12 || (Logical OR) L-R Write a program to display logic 0
13 ? : (Conditional Op.) R-L if one reads a digit character
14 = (Assignment) R-L through keyboard, otherwise 1.
15 , (Comma) L-R ASCII values for 0 to 9 are 48 to 57,
respectively.

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 21 / 22


.

Thank You

Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 February 03, 2020 22 / 22

You might also like