This document discusses structures in C programming. It explains that structures can contain elements of different data types, accessed by name, unlike arrays where all elements must be of the same type and accessed by index. It provides examples of declaring a structure type with members, defining structure variables, accessing members using the dot operator, passing structures to functions, and initializing an array of structures.
The document discusses call-by-value in function invocation in C. When a function is called, only the values of the arguments are passed to the function, not the variables themselves. So any changes made to the parameters inside the function are not reflected in the calling function. This causes an issue when trying to swap variables by passing them to a Swap function.
2. 2
Two-Dimensional Arrays
則 2谿 覦一 Syntax
data_type variable_name[ number][ number ];
Array dimensions
Declarations of arrays Remarks
int a[100]; a one-demensional array
int b[2][7]; a two-demensional array
int c[5][3][2]; a three-demensional array
3. 3
Two-Dimensional Arrays
則 int a[3][4] 朱Μ 覦一
a[0][0] a[0][1] a[0][2] a[0][3]
a[1][0] a[1][1] a[1][2] a[1][3]
a[2][0] a[2][1] a[2][2] a[2][3]
row 0
row 1
col 0 col 1 col 2 col 3
row 2
4. 4
Two-Dimensional Arrays
則 Two-Demensional Arrays #include <stdio.h>
#define M 3 /* number of rows */
#define N 4 /* number of columns */
int main(void){
int a[M][N], i, j, sum = 0;
for ( i = 0; i < M; ++i )
for ( j = 0; j < N; ++j )
a[i][j] = i + j;
for ( i = 0; i < M; ++i ) {
for ( j = 0; j < N; ++j )
printf(a[%d][%d] = %d ,
i, j, a[i][j] );
printf(n);
}
return 0;
}
a[0][0] = 0 a[0][1] = 1 a[0][2] = 2 a[0][3] = 3
a[1][0] = 1 a[1][1] = 2 a[1][2] = 3 a[1][3] = 4
a[2][0] = 2 a[2][1] = 3 a[2][2] = 4 a[2][3] = 5