First time here? Checkout the FAQ!
+1 vote


How will this get evaluated?

In general will *var be evaluated first, or will var++ be evaluated?

The answer is A, I have run it on IDE but how is it evaluated?

asked in Programming by Loyal (3.3k points)   | 47 views
how u can say int is 4 byte ???? it is compiler dependent.
I am not saying it. The question is implying it by default. Idk how to solve it.
Read operator precedence in C, only then you can attempt this question. Here confusing statement is *var2++=*var3++ --> here 3 operators are there i.e '=' , '++' , '*' --> read who has high precedence and solve it accordingly.
Wasn't able to find it on net. Is you have some link plz share

1 Answer

+3 votes
Best answer

Address of variables var2 and var3 are different.

after main() {

line no 3. var2 and var3, both pointing to same address, i,e &var1.

line no 4.  *var2++ = *var3++

*a++ can be written as:

here both * and ++ are unary operator precedence same but associaitvity right to left.

so (*(var2++)) = (*(var3++)), assignment has the least precedence among them (right to left), but increment is post, so variables' value (which is &var1) will increment after evaluation of expression.

It is just assigning 35 (*var3) to *var2 (which is var1), which was already 35, and they are incrementing var2 and var3 by 1×size_of_data_type

line no 5. var1++ ;  just increment 35 to 36.

Answer should be 36, var2, var3

= 36, &var1, &var1

Whatever the address of var1, it will be printed and both are equal.

answered by Loyal (3.7k points)  
selected by
I've ran the code on ide, address of var2 and 3 is same.
yes u are right. It is the address of var1, so it will be equal.
Top Users Jan 2017
  1. Debashish Deka

    8126 Points

  2. sudsho

    5042 Points

  3. Habibkhan

    4706 Points

  4. Vijay Thakur

    4458 Points

  5. Bikram

    4348 Points

  6. saurabh rai

    4212 Points

  7. Arjun

    4010 Points

  8. santhoshdevulapally

    3722 Points

  9. GateSet

    3292 Points

  10. Sushant Gokhale

    3286 Points

Monthly Topper: Rs. 500 gift card

19,122 questions
24,033 answers
20,276 users