[prev] [index] [next]

Exercise: Creating Objects via malloc()

Give variable declarations and statements that on the heap will create:

  1. a string buffer to hold strings of length K
  2. a vector of L double-precision floating point values
  3. an object of type Car, defined as:

    typedef struct {char rego[7]; float premium;} Car;
    

For each object:

  • draw a diagram of what it might look like in memory
  • show how you would initialise it to some plausible values