i have been working with this C problem for quite a while now, but dint get the satidfactory answer for it. i have got four pieces of code as follows:
code 1:-
#include <stdio.h>
int i=10;
int main()
{
printf("%d %d %d", ++i, ++i, ++i);
return 0;
}
output:
13 12 11
code 2:-
#include <stdio.h>
int main()
{
static int i=10;
printf("%d %d %d", ++i, ++i, ++i);
return 0;
}
output:
13 12 11
code 3:-
#include <stdio.h>
int main()
{
volatile int i=10;
printf("%d %d %d", ++i, ++i, ++i);
return 0;
}
output:
13 12 11
code 4:-
#include <stdio.h>
int main()
{
int i=10;
printf("%d %d %d", ++i, ++i, ++i);
return 0;
}
output:
13 13 13
i ran the above code on https://www.onlinegdb.com/, and the following results. i have gone through the concepts of precedence and associativity in c, and have a good understanding of memory segments and allocation in c and thus understand the working of static and volatile keywords, but even after going through the concepts again and again i an not able to understand why the results of code 1, 2, 3 are coming out to be 13 12 11 shouldnt they give the same results as code 4, that is 13 13 13.
i was expecting that code 1, 2, 3 should be resulting in the same results as code 4. but they are not.