I have some ideas of what this would do, but I'd like a more professional and experienced explaination.
typedef struct{
char str[50];
unsigned short num;
}s;
s *name = (s *) malloc(sizeof(s));
The first part defines a struct. I have no problem with that
This will create a pointer to "s" struct. malloc()
returns a memory address that will be cast as a pointer to "s". However, sizeof(s)
I Believe I am having some issues understanding.
char str[50];
= 50 bytes.
unsigned short num;
= 2 bytes.
sizeof(s) returns 52 bytes?
malloc(sizeof(s))
allocates 52 bytes and returns the first address and casts it as a pointer to "s"?
One More Question! How can I perform error handling with malloc in-line?
Thanks to anyone that can help clarify this!