I was trying to define structure having an int and string type members.
typedef struct emp{
int sno;
string name;
}
When I allocated space using malloc
and modified the name variable, it gives Segmentation Fault
.
I searched on stackoverflow and found solution to use char*
instead of string
type. Is it because char*
has a fixed size (pointer size)?
Also how does sizeof
treats a string variable since its length is not known before allocation?