Writing to Arrays
Understand how to write values to specific array cells safely and the risks of out-of-bounds access in C. Learn different methods to initialize one-dimensional arrays, including partial initialization, and discover principles for working with multi-dimensional arrays to handle complex data efficiently.
We'll cover the following...
We'll cover the following...
Assigning values to array cells
A memory location indexed by an array (for example grades[3]) is called a cell of that array. Just like we index an array to retrieve the value stored in it, we can also write to the same cell.
We can assign the integers 1 through 5 to the cells in our grades array like this:
What can be dangerous however, is that we can also ask C to assign values to memory locations beyond the bounds of an array and C won’t complain:
The reason this is ...