Question: Note: REVIEW. Please answer all coding questions with valid C code. You may assume for any question that the appropriate includes have been made and

Note: REVIEW. Please answer all coding questions with valid C code. You may assume for any question that the appropriate includes have been made and that i, j and k are declared and ready to use as integer variables (as loop indexes).

Part I - Dynamic Memory Allocation

For each of the following questions, you may assume that both size1 and size2 are integer variables that have been assigned to values prior to the line of code you are to write.

1) Write a single line of code that dynamically allocates an array of size1 variable of type double. Assign the memory allocated to a pointer called prices.

________________________________________________________________ 

2) Write a single line of code that frees the memory allocated in question 1.

________________________________________________________________ 

3) Write a segment of code that allocates a two dimensional array of characters with dimensions size1 bysize2. The array should be prepared to hold size1 strings of length size2-1 or less. Assign the memory allocated to a pointer called words.

________________________________________________________________ ________________________________________________________________ ________________________________________________________________

4) Write a segment of code that frees the memory allocated in question 3. ________________________________________________________________ ________________________________________________________________ ________________________________________________________________

5) This question involves the following struct:

struct student { char* name; 

int ID;

 double balance; }; 

Assuming that all pointers are stored using 8 bytes, integer are stored using 4 bytes, and doubles are stored using 8 bytes, what is the value of the expression sizeof(struct student)?

______________ 

6) Write a segment of code that allocates an array of pointers to struct student of length size1, then allocates each of the struct student variables, followed by allocating the name pointer in each of the structs to a character array of length size2. (Note: there are multiple possible orders for allocating the necessary memory and you may answer with any of these.)

________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ 

7) Write a segment of code that frees all of the memory allocated in question 6.

________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________ ________________________________________________________________

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!