[prev] 59 [next]

  1. Speeding tickets:

    typedef struct {
    	int day, month; } DateT;
    typedef struct {
    	int hour, minute; } TimeT;
    typedef struct {
    	char plate[7]; double speed; DateT d; TimeT t; } TicketT;
    

    TicketT *tickets;
    tickets = malloc(1000 * sizeof(TicketT));
    assert(tickets != NULL);
    

    32,000 bytes allocated

  2. Matrix:

    float **matrix;
    
    // allocate memory for m pointers to beginning of rows
    matrix = malloc(m * sizeof(float *));
    assert(matrix != NULL);
    
    // allocate memory for the elements in each row
    int i;
    for (i = 0; i < m; i++) {
       matrix[i] = malloc(n * sizeof(float));       
       assert(matrix[i] != NULL);
    }
    

    8m + 4·mn bytes allocated