c - How can a function create a struct? -
one of assignments c programming course define function called create_card. function receives suit character , card value, , returns card_t struct.
question: how function supposed create struct? can't create values struct? did misinterpret meaning of question or assignment written down wrong?
this example of function returning struct.
struct test { int a; }; struct test fun(int k) { struct test d; d.a=k; return d; }
replace struct test
name of struct , definition of struct test
struct's definition.
how use
int main() { struct test test=fun(6); printf("%d",test.a); // prints '6' return 0; }
Comments
Post a Comment