In Problem Set 4 we're given the copy.c and bmp.h files. On line 47 the fread() function is called with the arguments, &bf, sizeof(BITMAPFILEHEADER), 1, and inptr. I understand what each of these arguments mean: the first is the location in memory to the struct bf, second is the size, third is how many times we read it and fourth is the file pointer.

Now what I don't understand: How does the data get added to the struct in the proper order? How does every value align perfectly? In my understanding, it goes to the location (&bf) of the struct in memory, and just inserts all the numbers in a long sequence after each other and since the struct is a specific (total) size, all values get automatically aligned perfectly, since the next one starts when the last one ends. But this assumes structs are formatted like that in memory, and if this was the case, why can't I just say &bf = [long sequence of digits]? I tried this in another program and I got an error saying "expression is not assignable". So if this doesn't work, how does numbers get assigned to it's proper memory slot when using fread()?

EDIT: To clarify a bit more. When working with structs, I thought you had to specify each value individually, like bf.bfType = [type], bf.bfSize = [size], and so on... but instead we're just specifying the whole struct and the values get sorted to the right datatypes automatically.

EDIT#2: Seems my thinking was correct, but my syntax was off. The correct syntax that aligns with what I was trying to understand would be BITMAPFILEHEADER bf = {x, x, x, x, x}; for each of the values in the struct. You can't assign in this way however, only initialize, even when using the & operator. This part I don't understand. Why can fread do this but I can't manually? Is it just C syntax preventing me for whatever reason or what? I think it's not a matter of logic error any longer, but a limit of the language that I don't understand.