What's the difference between initializing this structure with these strategies?

Posted by mystify on Stack Overflow See other posts from Stack Overflow or by mystify
Published on 2010-06-01T16:57:58Z Indexed on 2010/06/01 17:03 UTC
Read the original article Hit count: 176

Filed under:
// the malloc style, which returns a pointer:
struct Cat *newCat = malloc(sizeof(struct Cat));

// no malloc...but isn't it actually the same thing? uses memory as well, or not?
struct Cat cat = {520.0f, 680.0f, NULL};

Basically, I can get a initialized structure in these two ways. My guess is: It's the same thing, but when I use malloc I also have to free() that. In the second case I don't have to think about memory, because I don't call malloc. Maybe.

When should I use the malloc style, and when the other?

© Stack Overflow or respective owner

Related posts about c