














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Explanation in details about operators and expressions in C Programming
Typology: Slides
1 / 22
This page cannot be seen from the preview
Don't miss anything!















Definition “An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and variables” Ex: a+b
Operator example Meaning
Operator Meaning < Is less than <= Is less than or equal to > Is greater than >= Is greater than or equal to == Equal to != Not equal to
a b Value of the expression a && b a || b 0 0 0 0 0 1 0 1 1 0 0 1 (^1 1 1 )
Syntax: v op = exp; Where v = variable, op = shorthand assignment operator exp = expression Ex: x=x+ x+=
C supports 2 useful operators namely
Syntax: exp1? exp2 : exp Where exp1,exp2 and exp3 are expressions Working of the? Operator: Exp1 is evaluated first, if it is nonzero(1/true) then the expression2 is evaluated and this becomes the value of the expression, If exp1 is false(0/zero) exp3 is evaluated and its value becomes the value of the expression Ex: m=2; n= r=(m>n)? m : n;
These operators allow manipulation of data at the bit level Operator Meaning & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR << Shift left >> Shift right
Algebraic expression C expression axb-c ab-c (m+n)(x+y) (m+n)(x+y) ab/c 3x 2 +2x+1 3xx+2x+ a/b S=(a+b+c)/ c ab b a 2 a b c S=
Algebraic expression C expression area= area=sqrt(s(s-a)(s-b)(s-c)) sin(b/sqrt(aa+bb)) tow1=sqrt((rowx-rowy)/2+towxyy) tow 1 =sqrt(pow((rowx-rowy)/2,2)+towxyy) y=(alpha+beta)/sin(theta3.1416/180)+abs(x)** s ( s a )( s b )( s c ) Sin 2 2 a b b 2 1 2 xy x y 2 2 1 2 xy x y y x sin
Rules for evaluation of expression
Operator Description Associativity ( ), [ ] Function call, array element reference Left to Right +, - , ++, - - ,!,~,*,& Unary plus, minus, increment, decrement, logical negation, 1’s complement, pointer reference, address Right to Left *, / , % Multiplication, division, modulus Left to Right