|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int NUM_ROWS = 4;
const int NUM_COLS = 3;
float alpha[NUM_ROWS][NUM_COLS];
alpha[1][2] = 12.8;
enum Colors
{RED, YELLOW, GREEN, BLUE, N_COLORS};
enum Makes
{FORD, TOYOTA, BMW, VW, GMC, N_MAKES};
float ticket[N_COLORS][N_MAKES];
ticket[BLUE][VW] = 0.75;
ticket[RED][BMW] = 1.46;
const int NUM_ROWS = 40;
const int NUM_COLS = 35;
int table[NUM_ROWS][NUM_COLS];
long rowSum[NUM_ROWS];
long colSum[NUM_COLS];
int row;
int col;
// sum the rows
for (row = 0; row < NUM_ROWS; row++)
{
rowSum[row] = 0;
for (col = 0; col < NUM_COLS;
col++)
rowSum[row]
+= table[row][col];
}
// sum the columns
for (col = 0; col < NUM_COLS; col++)
{
colSum[col] = 0;
for (row = 0; row < NUM_ROWS;
row++)
colSum[col]
+= table[row][col];
}
int table[2][3]
{
{14, 3, -5},
{0, 46, 65}
};
void Fun(float list[], int size)
{
. . .
}
void Fun(float table[][5], int rows, int cols)
{
. . .
}
You can specify both dimensions if you choose to.
void Fun(float table[2][5], int rows, int cols)
{
. . .
}
int table[4][2];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C++ computes the actual memory location for the elements from its indices and the number of items in each row. table[2][1]is at 6th location in the array, starting with the base address.
const int MAX_STUDENTS = 150;
typedef char String20[21];
String20 student[MAX_STUDENTS];
which is equivalent to:
char student[MAX_STUDENTS][21];
float
temp[100][100][10][24];
This would allow for 240,000 readings.
Each reading would be indexed by an x position (0 - 99), a y position (0
- 99), an altitude (0 - 9), and an hour (0-23).
typedef float Day[24];
typedef DayTemp Altitude[10];
Altitude temp[100][100];