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.

Operator

Description

Associativity

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

left-to-right

++ --
+ -
! ~
(type)
*
&
sizeof
Prefix increment/decrement
Unary plus/minus
Logical negation/bitwise complement
Cast (convert value to temporary value of type)
Dereference
Address (of operand)
Determine size in bytes on this implementation
right-to-left
*  /  %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
left-to-right
==  !=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
=
+=  -=
*=  /=
%=  &=
^=  |=
<<=  >>=
Assignment
Addition/subtraction assignment
Multiplication/division assignment
Modulus/bitwise AND assignment
Bitwise exclusive/inclusive OR assignment
Bitwise shift left/right assignment
right-to-left

,

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.
...