r/C_Programming • u/jombrowski • Jun 05 '26
Shellbonacci
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv)
{
if(argc < 2)
return 0;
int n = atoi(argv[1]);
if(n >= 2)
{
char bfr1[1000], bfr2[1000];
sprintf(bfr1, "%s %d", argv[0], n - 1);
sprintf(bfr2, "%s %d", argv[0], n - 2);
n = system(bfr1) + system(bfr2);
}
printf("%d\n", n);
return n;
}
13
Upvotes
View all comments
Show parent comment
2
u/flyingron Jun 06 '26
No, it is NOT. The order is unspecified (because it is communitive and the guys who designed see wanted to give flexibility to the code generator).
While it makes no difference to ADDITION if you do a + b or b + a, this isn't just addition. Those function calls have side effects (they print a value). The evaluation of the function calls is even independent of the addition itself.