本文介绍了帮助处理代码段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的计算机课有一个带回家的决赛,它有一个奖金

关于

的问题我们没有时间去编程覆盖。我已经在课堂上获得了一个A
,所以

这不会影响我的成绩,不过我的痴迷/

强迫性倾向

只是不能放手。我可以帮助解释一下这个

代码片段的作用;


char foo [8] =" bcd f\\\
\ 0" ;;

int i = 2;


while(foo [i ++])putchar(foo [i]);


提前致谢,

美洲狮

I''ve got a take home final for my computer class and it has a bonus
question concerning
some programming that we didn''t have time to cover. I''ve already got
an A in the class, so
it won''t affect my grade one way or another, however my obsessive/
compulsive tendencies
just can''t let it go. Could I get some help in explaining what this
code snippet does;

char foo[8]=" bcd f\n\0";
int i=2;

while (foo[i++]) putchar(foo[i]);

Thanks in advance,
Cougar

推荐答案



为什么不试试?


-

rbh

Why don''t you try it?

--
rbh




为什么不试试?


-

rbh


Why don''t you try it?

--
rbh



好​​吧,我没有机会使用C所以我不能尝试。从我已经得到的内容中,可以从书中收集出来的是,它宣布了一个8元/ b $ b整数的数组

并且增加了它在每个循环期间2。我不明白''bcd''

部分。

有人可以帮我一把吗?

Well, I don''t have access to C so I can''t try it. From what I''ve been
able to glean from the book is that its declaring an array of 8
integers
and increasing it by 2 during each loop. I don''t understand the ''bcd''
part.
Can someone give me a hand?




声明一个8个字符的宽阵列,投入'''',''b'','''','''','/'
''''''''''''''\\ n '',''\'''(''\ n''是换行符,''\'''是空终止

字符)

然后声明int i,稍后将其用作索引。它开始于

位置二(第三个字符,c,在数组foo中)


而(foo [i ++])putchar(foo [i] );


与...基本相同...


而(foo [i])

{

i ++;

putchar(foo [i]);

}


null终止character(''\''')是唯一一个'/ b>
为整数的字符,它将终止循环。因此,虽然当前索引处的

字符不是空终止符,并且在

递增索引之后,将字符打印到stdout。

对''c'的计算结果为true,然后递增,并打印出''d''。

然后它为''d'计算为true并打印下一个字符,一个空格。

然后它评估空间的真实性并打印下一个字符,

''f''等......直到它最终评估为'' \'''(在C中,零是

被认为是假的,其他任何东西都被认为是真的)。​​


这有什么帮助吗?得到A好工作!


-Dan

Declares an 8-character wide array, and puts in it '' '', ''b'', ''c'', ''d'',
'' '', ''f'', ''\n'', ''\0'' (''\n'' is newline, ''\0'' is the null terminating
character)
Then int i is declared, and later is used as an index. It starts at
position two (the third character, c, in the array foo)

while(foo[i++]) putchar(foo[i]);

Is essentially the same as...

while(foo[i])
{
i++;
putchar(foo[i]);
}

The null terminating character (''\0'') is the only character that''s
zero as an integer and will terminate the loop. So , while the
character at the current index is not the null-terminator, and after
incrementing the index, print the character to stdout.
It evaluates to true for ''c'', then is incremented, and prints out ''d''.
Then it evaluates true for ''d'' and prints the next character, a space.
Then it evaluates true for the space and prints the next character,
''f'', etc... Until it finally evaluates false for ''\0'' (In C, zero is
considered false and anything else is considered true).

Did this help at all? And good job getting an A!

-Dan


这篇关于帮助处理代码段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 12:46