#include<stdio.h>
main()
{
int a=10;
printf("%d %d %d\n",a=10,a=20,a=30);
}
o/p: 10 10 10.
Here, the latest value is updated and printed as the expression statements separated by commas in funtions are evaluted from right to left.
But, in below program by using global variable or static variable why the updated value is not printed??
#include<stdio.h>
int a=10;
main()
{
printf("%d %d %d\n",a=10,a=20,a=30);
}
o/p: 10 20 30.
For static variable,
#include<stdio.h>
main()
{
static int a=10;
printf("%d %d %d\n",a=10,a=20,a=30);
}
o/p: 10 20 30