Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C Programming Operators: A Comprehensive Guide with Examples and FAQs - Prof. sirohi, Lecture notes of Computer Science

A comprehensive overview of operators in c programming, covering various types like arithmetic, relational, logical, bitwise, and assignment operators. It explains their functionality, precedence, and associativity with clear examples. The document also includes a quiz section to test understanding and a faq section addressing common questions about operators in c.

Typology: Lecture notes

2024/2025

Available from 12/11/2024

anuj-sirohi-1
anuj-sirohi-1 🇮🇳

3 documents

1 / 24

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programming for Problem Solving (PPS)
Operators
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download C Programming Operators: A Comprehensive Guide with Examples and FAQs - Prof. sirohi and more Lecture notes Computer Science in PDF only on Docsity!

Programming for Problem Solving (PPS)

Operators

Topics

• Operators

• Precedence and Associativity

Types Of Operators

• Arithmetic

• Relational

• Logical

• Bitwise

• Assignment

• Increment/Decrement

• Conditional

• Special Operators

Arithmetic

OPERATION OPERATOR SYNTAX COMMENT RESULT Multiply * a * b result = a * b 27 Divide / a / b result = a / b 3 Addition + a + b result = a + b 12 Subtraction - a - b result = a – b 6 Modulus % a % b result = a % b 0 For a=9, b=

Logical

OPERATOR MEANING EXAMPLE && LOGICAL AND (6>5) && (7>9) GIVES 0 || LOGICAL OR (6>5) || (7>9) GIVES 1 ! LOGICAL NOT !(6>5) GIVES 0

Bitwise

OPERATOR MEANING EXAMPLE & BITWISE AND 5 & 6 GIVES 4 0101 & 0110 = 0100 | BITWISE OR 5 | 6 GIVES 7 ^ BITWISE X-OR 5 ^ 6 GIVES 3 << BITWISE LEFT SHIFT 5<<2 GIVES 20

BITWISE RIGHT SHIFT 5>>2 GIVES 1 ~ BITWISE NOT ~6 GIVES -

Increment/Decrement

OPERATOR MEANING EXAMPLE ++ INCREMENT A++ INCREMENTS THE VALUE OF A TO 1 -- DECREMENT A– DECREMENTS THE VALUE OF A TO 1

Conditional

OPERATOR MEANING EXAMPLE ? : TERNARY OPERATOR A>B?A:B

Precedence and Associativity

Precedence and Associativity

• Precedence of the operators describe about the

order of evaluation of the operators.

• Operators are grouped together and each group is

given a precedence level.

• Operators of higher precedence are always

evaluated first.

• Precedence is always applied before associativity.

• When two or more operators have the same

precedence level, then they are evaluated either

left-to-right or right-to-left.

Operator Description Associativity Precedence Level +

- Addition operator Subtraction operator Left-to-right 4 >> << Right shift operator Left shift operator Left-to-right 5 **< <=

=** Less than Less than or equal operator Greater than

Greater than or equal to Left-to-right 6 == != Equal to Not equal to Left-to-right 7 & Bitwise AND (^) Left-to-right 8 ^ Bitwise XOR (^) Left-to-right 9 | Bitwise OR (^) Left-to-right 10 && Logical AND (^) Left-to-right 11 || Logical OR (^) Left-to-right 12

? : Conditional operator^ Right-to-Left 13

**Operator Description Associativity Precedence Level

= /= %= += -= &= ^= |= <<= >>=* Assignment operator Right-to-Left 14 , Comma operator^ Left-to-right^15

Quiz

  • (^) If k=5, then value of variable x after the execution of a C statement x= k++ will be a. 6 b. 5 c. Randomly any one of the above d. Value of x will not depend on k Ans: b
  • (^) The operator && is a symbol of ________ operator.
  • (^) << is a symbol of ___________ operator.
  • (^) Arithmetic operators can be combined with assignment operators to form new operators in C. a. True b. False Ans: a
Logical AND
Bitwise Left Shift

FAQ’s