Puzzle T9

malloc a bulb struct

Allocate Memory for a struct

Write a main() that has a variable that can point to struct Bulb. Allocate memory for a struct, assign the address to the variable, initialize and print the struct.

Use void *malloc(size_t size) for allocating memory.

Use void free(void *address) for deallocating memory.

#include <stdio.h>

struct Bulb
{
  int watts;
  int lumens;
};

/* function to print a Bulb */
void printBulb()
{
}

int main()
{
  /* declare and initialize a Bulb pointer */
  struct Bulb *bptr;

  /* allocate memory for the Bulb */

  /* print the Bulb */

  /* deallocate memory for the Bulb */
  
	
  return 0;
} 


Answer         Next Page         Previous Page Home