Let's say you have a static array as an attribute of a struct
struct example {
char array [5];
};
struct example* exp = (struct example*)malloc(sizeof(struct example));
...initialize and so on...
Now is the static array in the struct considered to be on the heap or stack? In addition is it any more efficient to have an array with specified size in the struct vs a dynamically allocated array, i.e. a pointer that will point to the dynamic memory once you allocate it, attribute in terms of time to allocate? Lastily if it is on the stack does the stack eliminate the variable right when the struct is freed?
You are using the malloc function to allocate a memory.
So, using malloc function to allocate a memory for any variable, or a structure, it will allocate a memory in heap only.
You declaring a variable "a", this is the member of structure. So, in here you are not allocating a memory. You just declare a structure.
After that you allocating a memory using malloc, in here only the memory will be allocated in the heap.