I could not find an answer to this on the Internet, so here is my question: Can I define a struct instance without assigning it to a local or global variable in C? E.g.:
Yes, you can use compound literals in C99 and later.
return (struct A) { .b = 42 };
You can even point to them:
struct A *a = &(struct A) { .b = 42 };
a->b = 43;
These literals are "better" than string literals in that they are writable. The compiler may pool them if and only if you include const
in the literal's type .