c - Backward Analysis of Expression -


suppose have following code segment in c.

i = j = k = 1;  j = (i++) + (++k);  result = + j + k; //poi //expected result = 7 

here, want find value of result through backward analysis. when perform backward analysis, go through following expressions in order.

j = (i++) + (++k); ++k; i++; = j = k = 1; j = k = 1; k = 1; 

during backward analysis replace each variable corresponding expression, whenever applicable. i'm confused how deal increment/decrement operations.

my current strategy produce following result

result = + j + k  //after j = i++ + ++k result = (i+(i+(k+1)))+k  //after ++k result = (i+(i+((k+1)+1)))+(k+1)  //after i++ result = ((i+1)+((i+1)+((k+1)+1)))+(k+1)  //after = j = k = 1 result = ((1+1)+((1+1)+((k+1)+1)))+(k+1)  //after k = 1 result = (((1+1)+((1+1)+((1+1)+1)))+(1+1))  //simplifying result = 9 

which ofcourse not true.

can me this?

i think should more this

result = + j + k  //after j = x + y      // didn't analyse ++k , i++ yet  result = i+(x+y)+k      //after y = ++k result = (i+(x+(k+1))+(k+1)  //after x = i++ result = ((i+1)+(i+(k+1))+(k+1)  //after = j = k = 1 result = ((1+1)+(1+(k+1))+(k+1)  //after k = 1 result = ((1+1)+(1+(1+1))+(1+1)  //simplifying result = 7 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -