Program Ape---C language details 11 (array subscript out-of-bounds test, array subscript "," operator, side effect)

Source: Internet
Author: User
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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.