一个外星变量突然出现在阵列中 [英] An alien variable suddenly in an array

查看:72
本文介绍了一个外星变量突然出现在阵列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ħ!那里


我正在学习C ++。虽然这个网站的作者(称为CPlusPlus.com)似乎已经足够好了,但有时他会错过解释一些事情,我一直在想,直到我不断尝试并理解或推荐互联网。 />

这一次,它是我达到的阵列章节。在下面我给出的代码中,他从未首先解释为什么外星变量应该首先放在数组的方括号中,更不用说数组的所有数字如何自动累加,而不是给出任何此类指示。我猜第二个,假设相反,当你想要添加所有数字时,这就是你必须做的事情 - 这是它的公式。


在搜索更早的东西时,我碰巧到达了这个网站,并了解这里有一些好的专家。向我解释如何以及为什么要将外星变量放在数组的方括号内。

展开 | 选择 | 换行 | 行号

解决方案

我不知道外星变量是什么,我之前没有听过这个词。但如果你在谈论n,那是因为它被用来访问数组中的每个项目。


for循环将运行5次,设置n = 0,1,2,3,4。+ =运算符与获取现有值并添加它相同。


输出正确且程序正在运行因为它是假设的。


我会说你读得不对。阅读更多阅读简介。


您可能还会读到: http://bytes.com/topic/c/insights/77...rrays-revealed

H! there

I am learning C++. While the author of this website (called CPlusPlus.com) seems to be good enough, sometimes he does miss out on explaining a few things, that I keep wondering, till either I keep experimenting and thus understand, or refer the Internet.

This time, it is the arrays chapter I have reached. In the code I am giving below, he never explained in the first place why an alien variable should be in the array''s square brackets in the first place, let alone how all the figures of the array are adding up automatically, without having given any such instructions. The second one I guess, "assume" rather, that when you want to add up all the figures, this is what you have to do-- this is its formula.

While searching something earlier, I happened to reach this site, and understand there are a few good experts here. Explain to me too how and why should an alien variable be placed inside the square brackets of an array.

Expand|Select|Wrap|Line Numbers

解决方案

I don''t know what an alien variable is, I haven''t heard that term before. But if you''re talking about the n, that''s because it''s being used to access each item in the array.

The for loop will run 5 times, setting n = 0, 1, 2, 3, 4. The += operator is the same as taking the existing value and adding to it.


The output is correct and the program is behaving as it was suppose to be.

I will say you didn''t read properly. Read more read brief.


You might also read this: http://bytes.com/topic/c/insights/77...rrays-revealed


这篇关于一个外星变量突然出现在阵列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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