Arrays and bounds.
Understand contiguous elements, zero-based indexes, and why a pointer is not a length.
The idea behind the syntax.
An array is a contiguous sequence of elements of one type. Its declared extent determines how many elements it contains, and indexing begins at zero. For an array of three elements, indices 0, 1, and 2 are valid; index 3 is already one past the end and must not be read as an element. C performs no general runtime bounds check for an array access, so the program must carry the correct length through its logic.
A declaration with an initializer can let the compiler count elements. Inside the same scope, sizeof can reveal the total byte size of the array. But when an array is passed to a function, the parameter is adjusted to a pointer to its first element. The function receives an address, not an automatically attached length. That is why robust C interfaces usually take a pointer and a separate count.
What C guarantees.
A two-dimensional array is an array whose elements are themselves arrays. Its rows are stored contiguously in row-major order, and a function parameter for such an array must know the later dimension sizes to calculate addresses. This is different from an array of pointers to separately allocated rows. The memory shape determines what pointer type and indexing expression are valid.
Array elements can be changed in place. Copying an entire array with assignment is not allowed as it is for a struct, though a loop or library operation can copy individual bytes or elements when appropriate. A function that receives an int * may edit the caller's elements unless its parameter is const int *. The const qualifier makes a read-only intent visible to both compiler and reader.
Why the detail matters.
An array's type contains its element type and its extent, but most expressions convert the array to a pointer to its first element. The conversion is a language convenience, not a hidden copy of the data. Exceptions include sizeof applied directly to an array and taking its address with &, where the full array type still matters. This explains why sizeof works for count calculation in main but not for a parameter spelled with array brackets.
Bounds are a relationship between an access and the exact object it names. A function receiving pointer p and count n needs a caller guarantee that at least n elements of the correct type are accessible beginning at p. The compiler cannot infer that guarantee from a raw pointer. A const-qualified parameter prevents writes through that parameter, but it does not prove the pointer is non-null, correctly aligned, or long enough. Each part of the contract must be established separately.
See the rule in context.
#include <stdio.h>
#include <stddef.h>
int sum(const int *values, size_t count) {
int total = 0;
for (size_t i = 0; i < count; ++i) total += values[i];
return total;
}
int main(void) {
int values[] = {2, 3, 5};
size_t count = sizeof values / sizeof values[0];
printf("Sum: %d\n", sum(values, count));
return 0;
}main owns an array of three integers and calculates its length while it is still an array. Passing values supplies a pointer to its first element; count supplies the separate bound. sum reads exactly indices 0 through 2 and returns 10. The const parameter prevents sum from modifying those integers through this pointer. No allocation or hidden copy of the array occurs.
Where the rule stops.
The pointer and count must describe the same accessible region. A count larger than the actual array would make the loop read outside the object even though the function's types still match.
Keep this model.
Text in C is often stored in an array of char, but text adds a terminating zero byte and encoding questions. The next chapter explains why a string's allocated capacity and its current character length are different quantities.