Suppose I want to define a structure representing length of the vector and its values as:
struct Vector{ double* x; int n; };
Now,
When you malloc(sizeof(struct_name)) it automatically allocates memory for the full size of the struct, you don't need to malloc each element inside.
malloc(sizeof(struct_name))
Use -fsanitize=address flag to check how you used your program memory.
-fsanitize=address