user1.username = "Hellen";
This does not change the size of the structure, it just sets
to point to the string
, which is stored somewhere else in memory. If you now write the structure to a file, then you lose all the data, since all you are writing is two pointers and an integer. You would be better to use classes instead of structs, and study serialisation to ensure that you can persist your objects on disk when necessary.