As per my knowledge i know that when a structure is defined, no memory is assigned to its members but when a variable of that structure is declared memory is allocated and also this allocation takes place at runtime. Now my issue is that how is dynamic memory allocation different in case of structures(when variable of that structure is declared) and classes(where memory is allocated dynamically using new operator). whats the difference it both the allocation?
Now lets say i have a structure as shown below:-
struct abc
{
int a;
char str[10];
};
at this point memory is not allocated to a and str. It'll be allocated only if i do the following:-
struct abc var;
where var is a variable of type struct.
Now my question is how exactly the MEMORY IS ALLOCATED to structure members a and str? Is that similar to that allocated using new operator in case of class or different? Will it use stack or heap?
Now lets say i have a structure as shown below:-
struct abc
{
int a;
char str[10];
};
at this point memory is not allocated to a and str. It'll be allocated only if i do the following:-
struct abc var;
where var is a variable of type struct.
Now my question is how exactly the MEMORY IS ALLOCATED to structure members a and str? Is that similar to that allocated using new operator in case of class or different? Will it use stack or heap?
Comment