A
Army1987
(Not sure on whether the temporary plonk has expired, butKeith Thompson said:
3
Why, what were you expecting?
#include <stdio.h>
int main(void)
{
int i = 3;
if (getchar() = 'y')
i = i++;
printf("%d\n", i);
return 0;
}
What does it do if you input y? What does it do if you input n?
#include <stdio.h>
size_t counter(void)
{
static size_t count = 0;
return count++;
}
#define i a[counter()]
int main(void)
{
int a[2] = {23, 47};
i = i++;
printf("%d %d\n", a[0], a[1]);
return 0;
}
What does it do? It is allowed to print "24 23" or to print
"47 48", but not anything else. (The order of function calls is
unspecified, but they can't overlap, so the increment to count the
second time the function is called has to happen after the
sequence point due to the end of the return statement in the first
time.) And:
#include <stdio.h>
{
int a[2] = {0, 3};
int answer = (getchar() == 'y');
a[answer] = a[1]++;
printf("%d\n", a[1]);
return 0;
}
This must print 4 if I don't input y, but is allowed to do
anything if I do. <ot>But if it happened to do anything else than
printing 3 or printing 4, I would be extremely astonished and
curious about how the implementation works.</ot>