开发者

Can anyone explain this program? [closed]

开发者 https://www.devze.com 2023-02-09 00:54 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. 开发者_JAVA百科 Closed 10 years ago.
int array[2][2] = {0, 1, 2, 3};
int i;
int sum = 0;

for (i =0; i < 4; ++i)
{

    int x, y;

    x = i % 2;

    if (x)
    {
        y = 0;
        }
    else
    {
        y = 1;
        }
    sum += array[x][y];
}

printf("%d\n", sum);


It's short enough that you could walk through it yourself (since this is homework) and run each line yourself on paper. If there is any line that you can't figure out, ask a more specific question. Just use pencil, make a box to show the values of x, y, i, sum and all 4 elements of the array. Then walk through changing the values in those boxes as you examine lines of code and you will see exactly what's happening. One thing you should know is that "if (x)" will treat x as true when it is 1.

0

精彩评论

暂无评论...
验证码 换一张
取 消