CIS3355:
Business Data Structures |
How many bytes of storage do we need for a struct??
First... Keep in mind that a struct is an array with a fixed number of contiguous storage elements, but unlike an array, the struct elements do not need to be all of the same data type. Now... Lets say that we want to create list of banking customers We need to track the customer’s name, their account number, the date the account was opened, the balance of the account, and the account officer.
Now that we have everything, our struct will look like this:
We need 50 bytes of contiguous RAM storage for our data type struct customer.
Consider the Questions and answers below:
Question: If there are only 10 spaces, or bytes, needed for date_opened, why do we need 11 bytes? Answer: Because we need one additional bye for the ‘\0’, which comes after a character string. Question: Is a struct considered a data type, the same as an integer, a float, a character, or a pointer? Answer: Yes, when we set up a struct, such our struct customer, we are creating a new data type. Question: Once we store a struct, can we locate it later? Answer: As with all data types, a struct has a base address, since it has a fixed number of elements, if we know the base address, how many elements are in the stuct and their size, we can locate any portion of the struct that we wish to see. |