#include <stdio.h>
main()
{
int i=5;
printf("%d %d",i,i++);
}
Output: 6 5
Can someone please explain this kind of output? Has it something to do with the associativity of the comma operator?
#include <stdio.h>
main()
{
int i=5;
printf("%d %d",i,i++);
}
Output: 6 5
Can someone please explain this kind of output? Has it something to do with the associativity of the comma operator?
The behaviour is unspecified. This is because the arguments to printf
are not sequenced.
(Informally, you don't know when i
will be incremented).
The order of evaluation of the arguments inside is unspecified, so depending on your C compiler and options i
or i++
can get evaluated first. The output you receive is what happens when i++
gets evaluated before i
.