Main content: Array subscript out-of-bounds test, array subscript "," operator, side effect
#include <stdio.h>int main (int argc, char * * argv) {int a[2]={1,2},b[2] = {3,4};//output unknown value int i = 0;printf ("%d\n", b[0,2] ); The comma is an operator, b[0,2] is treated as b[2], where b[2] is out of //subscript, but the output is 1, is the value of a[0] (by changing the value of a[0] output also changed), //I tested the following several cases, The results are summarized in the loop with I do array subscript and //loop End conditions to special consideration do not cross the bounds, if the cross-border is likely to cross the array operation //will change the value of I, so that the loop can not end //int k = 6,b[2] = {3,4},a[2]={1,2}, j = 5;//Output unknown value, change to b[0,3] Output 6//int k = 6,a[2]={1,2},b[2] = {3,4};//output value 1//int a[2]={1,2},j = 5,b[2] = {3,4};//output unknown value, changed to B[0, 3] Output 5//int k = 6,a[2]={1,2},j = 5,b[2] = {3,4};//output unknown value, change to b[0,3] Output 5 while (I < 2) {A[i] = b[i++]; There are side effects}i = 0;while (I < 2) {printf ("a[%d] =%d\n", I, A[i]); i++;} return 0;}
Output:
Program Ape---C language details 11 (array subscript out-of-bounds test, array subscript "," operator, side effect)