Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
An array is a structured data type that is indexed by an integer value and contains elements all of the same type.
Consider the following program.
Here is the C code.
Here is the output of the C code.
2. Array bounds checking
C does not check array bounds accesses, so accesses out of bounds may or may not cause an error.
What is the output of the following program.
Here is the C code.
Here is the output of the C code.
3. Quirk in C/C++
In the original program, I had used y1 as a variable name, but that appears to be reserved for some math Bessel function, so the variable name was changed to w1. But in C, this appears to not be an issue (since math library not used), so the w1 was changed back to a y1.
4. Unexpected output
In the above program, x1, y1, and z1 are assigned values and output.
Then the array a1 is initialized but past the maximum array bounds. Those last three assignments overwrite x1, y1, and/or z1 (depending on the compiler). There are no error messages and no run-time errors - though that can happen.
When x1, y1, and z1 are again output, their values have changed.