A C array is a contiguous sequence of objects of one type. The length is part of the type when it is declared: int a[10]. Indexes start at 0. There is no .length field.
Mental model: the array object is the ten ints. In almost every expression, the name a decays to a pointer to the first element. After decay you no longer know the length. That is why functions take a pointer and a count.
int a[4]; /* uninitialized if local — indeterminate values */
int b[4] = {1, 2, 3, 4};
int c[] = {1, 2, 3}; /* length 3 inferred */
int d[4] = {1, 2}; /* rest zero */
int e[4] = {0}; /* all zero */
a = b does not compile. Copy with a loop or memcpy.int a[5] = {[2] = 7};int a[n]; is C99, optional in C11. Wave A: prefer a compile-time size or a pointer + malloc (Wave B).a[i]; /* *(a + i) */ i[a]; /* same, legal, never write this */
void f(int a[10]) the [10] is a lie: the parameter is int *. sizeof a inside f is sizeof(int *).void f(int *a, size_t n).void fill(int *a, size_t n, int v) {
for (size_t i = 0; i < n; i++) {
a[i] = v;
}
}
int m[2][3] = {{1, 2, 3}, {4, 5, 6}};
m[r][c];
int m[2][3] is an array of 2 arrays of 3 ints. Contiguous. m[0] decays to int *.void f(int m[][3], size_t rows) or a pointer to array int (*m)[3].int ** is not a 2D array. It is a pointer to pointer (ragged, separately allocated rows).int a[4] = {1, 2, 3, 4};
int b[4];
memcpy(b, a, sizeof a); /* #include <string.h> */
sizeof a is the whole array only while a is still an array object in this scope.sizeof a / sizeof a[0] — only for true arrays, never for decayed pointers.sizeof on a function parameter that “looks like” an array.int ** as int[][].{0} when you mean empty.memcpy / a loop, never assignment.~ Good luck with your revision! ~