-7

I have this code troubling me for a while.The expression at Line 7 is troubling me. Is it giving 0 or -1. If its 0 then answer is 2 else answer is 4.

/* How to find value of c in Line 7 expression */

#include<stdio.h>

int main()
    {
    int a,b,c=1;
    a=b=c;                         // a,b,c have equal value
    c=b+=a=-c;                     // what will be the output of this expression?
    c=-c;
    c=(++c)*2;                    
    printf(“%d”,c);
    return 0;
    }

2 Answers2

2

In C the pre-increment (decrement) and the post-increment (decrement) operators requires an L-value expression as operand. Providing an R-value or a const qualified variable results in compilation error.

An lvalue is a value that can be assigned to.

Sadique
  • 22,572
  • 7
  • 65
  • 91
2

/* what is value of c */

That's easy to answer: Your question does not make any sense.

Since your code won't compile, c won't have a "value".

Hans Klünder
  • 2,176
  • 12
  • 8