“我”的价值是怎样的?来了? [英] How did the value of "I" came ?

查看:103
本文介绍了“我”的价值是怎样的?来了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a[5]={5, 1, 15, 20, 25};
    int i, j, m;
    i = ++a[1];
    j = a[1]++;
    m = a[i++];
    printf("\n%d %d %d",i, j, m);
    return 0;
}





我的尝试:



我得到了输出。我可以理解j = 2和m = 20的值。但我无法理解i = 3的值如何。



What I have tried:

I got the output. And i can understand the values of j=2 and m=20. But i can't understand as how the value of i = 3.

推荐答案

运行它,找出...当你这样做时,你应该能够为你自己解决原因 - 这就是为什么你的老师把它作为你的作业,毕竟...



我们不做你的功课:它是为一个原因。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!



Run it, and find out ... and when you do, you should be able to work out why for yourself - that is why your teacher set it as your homework, after all ...

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!

引用:

是。我的问题被错误地放在了门户网站上。对不起。我已经以特定的方式更新了我的问题。





什么是 a [1]

这是一个简单的问题:值1.因此增加,2进入 i

然后再次从 a [1] 中提取该值:1。增加,并放入 j

然后使用 i - 包含2 - 从 a [2] 获取>值15,然后将 i 增加到3,然后将15放入 m



看看这里:为什么x = ++ x + x ++给我错误的答案? [ ^ ] - 它可能会让它更清晰。



What is in a[1]?
It's a simple question: the value 1. So that is incremented, and 2 goes into i.
The value is then pulled from a[1] again: 1. Incremented, and put into j.
You then use i - containing 2 - to fetch from a[2] the value 15, and then increment i to three, before putting 15 into m.

Have a look here: Why does x = ++x + x++ give me the wrong answer?[^] - it may make it a bit clearer.


读取你的代码小心地

read your code carefully
i = ++a[1];
j = a[1]++;//increment 1 (now two)
m = a[i++];//incrementing once again

我真的不喜欢一行中的陈述。奇怪错误的来源......

I really dislike to statements in one line. The source for strange bugs...


关于变量 i 请记住发生的事情(或在一张纸上) ,或在代码中插入注释):

Regarding the variable i just do in mind what is happening (or on a piece of paper, or by inserting comments in your code):
i = ++a[1];
// a[1] is 1
// ++ prefix: is 2
// 2 is assigned to i

// ...

m = a[i++];
// i is post incremented here: is 3


这篇关于“我”的价值是怎样的?来了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆