Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

well i got a question a in c . but i some of my friends get the answer as 9 and some get the answer as 11

–1 vote
asked Mar 25, 2018 by anonymous
int k = 2 ;

k += ++k + k-- / 3 + ++k

what is the value of K after evaluating the expression . And also can i know the steps as well .

thank you so much if someone could help as soon as possible

1 Answer

0 votes
answered Mar 27, 2018 by MaHi

as per C operator precedence

the value of k will be 9.

C Operator Precedence Table

This page lists C operators in order of precedence (highest to lowest). Their associativity indicates in what order operators of equal precedence in an expression are applied.




( )
[ ]
++ --
Parentheses (function call) (see Note 1)
Brackets (array subscript)
Member selection via object name
Member selection via pointer
Postfix increment/decrement (see Note 2)


++ --
+ -
! ~
Prefix increment/decrement
Unary plus/minus
Logical negation/bitwise complement
Cast (convert value to temporary value of type)
Address (of operand)
Determine size in bytes on this implementation
*  /  %Multiplication/division/modulusleft-to-right
+  -Addition/subtractionleft-to-right
<<  >>Bitwise shift left, Bitwise shift rightleft-to-right
<  <=
>  >=
Relational less than/less than or equal to
Relational greater than/greater than or equal to
==  !=Relational is equal to/is not equal toleft-to-right
&Bitwise ANDleft-to-right
^Bitwise exclusive ORleft-to-right
|Bitwise inclusive ORleft-to-right
&&Logical ANDleft-to-right
| |Logical ORleft-to-right
? :Ternary conditionalright-to-left
+=  -=
*=  /=
%=  &=
^=  |=
<<=  >>=
Addition/subtraction assignment
Multiplication/division assignment
Modulus/bitwise AND assignment
Bitwise exclusive/inclusive OR assignment
Bitwise shift left/right assignment


Comma (separate expressions)left-to-right

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.