Tommy
8/13/2008 3:49:00 AM
[cuitao@mytest c]$ vi pp.c
#include <stdio.h>
int main()
{
int x=10;
x=20;
printf("\nx=%d\n",x);
return 0;
}
~
~
~
"pp.c" 9L, 99C written
[cuitao@mytest c]$
[cuitao@mytest c]$
[cuitao@mytest c]$ cc ./pp.c -o ./pp
[cuitao@mytest c]$
[cuitao@mytest c]$ ./pp
x=20
[cuitao@mytest c]$
[cuitao@mytest c]$ vi pp.c
#include <stdio.h>
int main()
{
int x=10;
x++=20;
printf("\nx=%d\n",x);
return 0;
}
~
~
~
"pp.c" 9L, 101C written
[cuitao@mytest c]$
[cuitao@mytest c]$
[cuitao@mytest c]$ cc ./pp.c -o ./pp
../pp.c: In function `main':
../pp.c:5: error: invalid lvalue in assignment
[cuitao@mytest c]$ vi pp.c
#include <stdio.h>
int main()
{
int x=10;
++x=20;
printf("\nx=%d\n",x);
return 0;
}
~
~
~
"pp.c" 9L, 101C written
[cuitao@mytest c]$ cc ./pp.c -o ./pp
../pp.c: In function `main':
../pp.c:5: error: invalid lvalue in assignment
[cuitao@mytest c]$
"Eric Sosman" <esosman@ieee-dot-org.invalid>
??????:4sadnefSS4WSyT_VnZ2dnUVZ_jOdnZ2d@comcast.com...
> jackie wrote:
>> i know that in c plus plus,++x returns l-value while x++ returns r-
>> value,but what is the situation in c,are both ++x and x++ return r-
>> value? i don't know how C99 defines it,thx.
>
> In C (all versions), neither ++x nor x++ is an lvalue.
> I'm surprised to hear that this is different in C++, because
> it makes no sense to me. Is
>
> int x = 42;
> ++x = 97;
>
> legal in C++? If so, what is the value of x afterwards?
> (Actually, you can disregard the second question: If the
> answer to the first is anything other than "No," I don't
> want to know anything more about C++.)
>
> --
> Eric Sosman
> esosman@ieee-dot-org.invalid