Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Verify that the * operator works as expected by printing out the results of the

ID: 3573225 • Letter: V

Question

Verify that the * operator works as expected by printing out the results of the look-up: *cptr: 65 *nptr: 5000 * fpt: 12.884 Be able to explain and write memory tables for the following: Declaration of a regular struct or array variable Declaration of a pointer struct variable initialization of a pointer struct variable by using an existing variable Initialization of a pointer struct variable by using malloc Accessing/changing the value of each member variable of a structure for both regular variables (use .) and pointer variables (use rightarrow ). Declaring an array of structures using malloc. Write code to produce the memory table for you.

Explanation / Answer

a)
struct example{
   int data;
}start;

b)
struct example *ptr;

c)
ptr = &start;

d)
struct example *ptr1;
prt1 = (struct example)malloc(sizeof(struct example *))

e)
//changing value
ptr.data = 10;
ptr1->data = 20;

//Accessing
ptr.data
prt1->data

f)
//dynamic arrays
struct example *ptr2 = (struct example)malloc(sizeof(struct example));