Just the opposite.
All the operands are evaluated from left to right, and the right most operand is returned as the value of whole comma expression.
But remember the operator precedence. Comma is lower than assignment.
So c=--a, b++ - c is equivalent to c=--a; b++ -c;
While  c=(--a, b++ -c) is equivalent to --a; c=(b++-c).

#include<stdio.h>
int main()
{
  int a=1,b=2,c=3;

  c=--a,b++ - c;

  printf("%d %d %d",a,b,c);
  return 0;
}
Output: 0 3 0

#include<stdio.h>
int main()
{
  int a=1,b=2,c=3;

  c=(--a,b++ - c);

  printf("%d %d %d",a,b,c);
  return 0;
}
Output: 0 3 -1


On 2010-12-14 22:12, KK wrote:
ya all the exprn is evaluated and left expr is assigned ..

On Dec 13, 9:21 pm, siva viknesh<sivavikne...@gmail.com>  wrote:
#include<stdio.h>
int main()
{
  int a=1,b=2,c=3;

  c=--a,b++ - c;

  printf("%d %d %d",a,b,c);
  return 0;

  }

the above code is perfectly valid and prints "0 3 0" ...

but how "comma" is evaluated and the value assigned to variable 'c' is the
expression evaluated on the RHS of comma....is there any such rules in C ??

--
You received this message because you are subscribed to the Google Groups "Algorithm 
Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to