Overlooking the fact that the code you've provided won't compile at all ...
Your function
course()
returns a struct, but that doesn't get assigned in the little bit of
main()
you've provided. Going back to basics - suppose we have a function f that takes an int as an argument, and returns an int value:
int f(int x);
f(2);
f();
int i;
i = f(2);
printf("i = %d\n", i);
printf("f(3) = %d\n", f(3));
In your case, you want to do either of the following:
struct Credit MyCredit;
struct Intermediate MyIntermediate;
MyCredit = course(12, 10, 10, 8);
MyIntermediate = grade(MyCredit);
or
struct Intermediate MyIntermediate = grade(credit(12, 10, 10, 8));
You would use the second example if you didn't need to use the return value of course() again later.
Normally, though, we do not pass or return structs to or from functions. That's because C uses pass-by-value, which means that when you pass or return a struct the compiler copies the struct to/from the stack as needed. For a small struct, that's generally not a problem. But if you have a large struct that takes up several kilobytes (or even megabytes!), you're copying that data for each function call or return. An alternative approach
might be:
void course(struct Credit *credit, float x1, float x2, float y1, float y2)
{
credit->A = x1+x2;
}
int main()
{
struct Credit MyCredit;
course(&MyCredit, 12, 10, 10, 8);
return 0;
}
In this case, we never add more than the size of a pointer (normally 4 bytes for 32 bit system, 8 bytes for 64 bit systems) to the stack.