I apologize if this is exceptionally elementary, but I just started programming in school, I have looked all over for the solution and unfortunately nothing has helped me with this. I have this piece of code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int logic(int a, int b)
{
int c = a % b;
a++;
b--;
printf("==%d %d %d==\n", a, b, c);
return b + a + c;
}
int main()
{
int a, c;
float d, f;
a = 10;
c = 5;
f = 2;
d = logic(a, logic(c, f));
printf("%d %d %.2f %.2f\n", a, c, d, f);
return 0;
}
Now the output for this is:
'== 6 1 1==
==11 7 2==
10 5 20.00 2.00'
Now the problem is how does the line 'd = logic(a, logic(c, f));'
compile in regards to the logic function above. I assume to get the first output, the logic function takes the value of 5 and 2 for c and f and runs it through the function for a and b. But I am totally stumped as to why the next output is '==11 7 2=='
. What does return 'c + b + a;'
do exactly, when I replace the + operator with a comma only the first value in the output (which is 11 regardless of what order I place the variables) emerges, the rest are 0s.
Please help with this, I am incredibly stumped, have been at it for hours and still nothing.