我的问题 [英] i++ question
问题描述
嗨:
请看下面的代码:
int a [3] = {1,3,2 };
int b [3] = {7,9,10};
int i;
i = 0;
a [i ++] = b [i ++];
for(i = 0; i< 3; i ++)
printf(" a [%d]:%d,b [%d]:%d \ n",i,a [i],i,b [i]);
输出是什么?
我在两个不同的平台linux和irix下运行它,得到两个不同输出的
。有人可以告诉我为什么吗?
非常感谢,
bo
Bo Sun< b0 ***** @ cs.tamu.edu>写在
新闻:Pi ******************************* @ unix.cs.tam u.edu:
嗨:
请看下面的代码:
int a [3] = { 1,3,2};
int b [3] = {7,9,10};
int i;
i = 0;
a [i ++] = b [i ++];
你不能这样做!使用两个不同的索引并避免未定义的
行为。请阅读此常见问题解答。
-
- 马克 - >
-
2003-12-18,Bo Sun< b0 ***** @ cs.tamu.edu>写道:i = 0;
a [i ++] = b [i ++];
这是一个comp.lang .c常问的问题。请阅读C-faq中问题3.1的
答案。
http://www.eskimo.com/~scs/C-faq/top.html
- James
-
Bo知道C.阅读C-faq!
< blockquote>
Bo Sun写道:
嗨:
请看下面的代码:
int a [3] = {1,3,2};
int b [3] = {7,9,10};
int i;
i = 0;
a [i ++] = b [i ++];
注意^
for(i = 0; i< 3; i ++)
printf(" a [%d] :%d,b [%d]:%d \ n",i,a [i],i,b [i]);
输出是什么?
<我在两个不同的平台linux和irix下运行它,得到两个不同的输出。有人可以告诉我为什么吗?
数组分配中没有中间序列点
" a [i ++] = b [我++]" ;.参见
http://publications.gbdirect.co .uk / c ... ce_points.html
了解详情。
Ed。
hi:
please take a look at the following code:
int a[3] = {1, 3, 2};
int b[3] = {7, 9, 10};
int i;
i = 0;
a[i++] = b[i++];
for (i = 0; i < 3; i ++)
printf("a[%d]: %d, b[%d]: %d\n", i, a[i], i, b[i]);
what is the output?
I run it under two different platform, linux and irix, and get two
different output. Can someone tell me why?
many thanks,
bo
Bo Sun <b0*****@cs.tamu.edu> wrote in
news:Pi*******************************@unix.cs.tam u.edu:
hi:
please take a look at the following code:
int a[3] = {1, 3, 2};
int b[3] = {7, 9, 10};
int i;
i = 0;
a[i++] = b[i++];
You cannot do this! Use two different indexes and avoid the undefined
behavior. Please read the FAQ on this.
--
- Mark ->
--
On 2003-12-18, Bo Sun <b0*****@cs.tamu.edu> wrote:i = 0;
a[i++] = b[i++];
This is a comp.lang.c frequently asked question. Please read the
answer to question 3.1 in the C-faq.
http://www.eskimo.com/~scs/C-faq/top.html
-- James
--
Bo knows C. Read the C-faq!
Bo Sun wrote:
hi:
please take a look at the following code:
int a[3] = {1, 3, 2};
int b[3] = {7, 9, 10};
int i;
i = 0;
a[i++] = b[i++];
Note^
for (i = 0; i < 3; i ++)
printf("a[%d]: %d, b[%d]: %d\n", i, a[i], i, b[i]);
what is the output?
I run it under two different platform, linux and irix, and get two
different output. Can someone tell me why?
There are no intermediate sequence points in the array assignment for
"a[i++] = b[i++]". See
http://publications.gbdirect.co.uk/c...ce_points.html
for details.
Ed.
这篇关于我的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!