that depends types

for exemple string[255] is an array of 256 char, a string type always contains a 0 terminal, so if your string is 50 long, theres one 0 after, and 205 char of random memory. when you read your record in a file, you obtain the original string just because there's a trailing 0.

for an integer type, the size of an integer is fixed and know by advance, that's why you can write stream.write(i, sizeof(integer))

i don't know if i'm understable...