...
Code Block | ||
---|---|---|
| ||
enum { TABLESIZE = 100 }; int *table = NULL; int insert_in_table(int pos, int value){ if (!table) { table = (int *)malloc(sizeof(int) * TABLESIZE)new int[TABLESIZE]; } if (pos >= TABLESIZE) { return -1; } table[pos] = value; return 0; } |
...
Code Block | ||
---|---|---|
| ||
enum { TABLESIZE = 100 }; int *table = NULL; int insert_in_table(size_t pos, int value){ if (!table) { table = (int *)malloc(sizeof(int) * TABLESIZE)new int[TABLESIZE]; } if (pos >= TABLESIZE) { return -1; } table[pos] = value; return 0; } |
...
Code Block | ||
---|---|---|
| ||
template <typename T> void clear(T array[], size_t n) { for (size_t i = 0; i < n; ++i) { array[i] = 0; } } template <typename T, size_t n> inline void clear(T (&array)[n]) { clear(array, n); } int int_array[12]; clear(int_array); // deduce T is int, and that n is 12 |
...