Conceptual Questions - Please help!

Assume ints require one cell in memory, that a float number requires two cells and that the struct members are found in contiguous memory location with no gaps.

1
2
3
4
5
6
7
8
9
10
typedef char String[10];
struct StudentRecord;
{
  String firstName;
  String lastName;
  int id;
  float gpa;
  int currentHours;
  int int totalHours;
};


1). If the base address of student is 100, what address does the compiler generate as the target of the following assignment statement?
student.gpa = 3.87;

2). How much space does the compiler set aside for students?


I have no idea of what the question means and don't know how to answer those questions. Please Help !!
The questions are intended to help you understand how the compiler allocates memory.

The instructions don't state how much space a char takes, but lets assume one cell. You're told that base address of student is 100. Since a string is defined to be 10 chars, we know that firstName occupies cells 100-109. Likewise, lastName occupies cells 110-119. You should be able to work out where id and gpa start.

For the second question, simply add up the size of the individual elements.

@ AbstractionAnon,
Thank you! It makes sense.
Topic archived. No new replies allowed.