数组超出界限 [英] Array Out Of Boundaries

查看:79
本文介绍了数组超出界限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int main()

{


int i,j;

int k [] = {1,2 ,3,4,5};

k [5] = 50;

printf("%d%d",i,j);

}


这个程序编译正常,结果是-858993460 50

我无法找到为什么打印上述值。请求帮助

这个

解决方案



krish写道:


int main()

{


int i,j;

int k [] = {1,2,3,4,5};

k [5] = 50;

printf("%d%d" ,我,j);

}


这个程序编译正常,结果是-858993460 50

我无法找出为什么打印上述值。请求帮助

就此而言。



嘿,索引从0开始。所以数组中有5个元素

从0到4开始。所以k [5 ]将是阵列之外的第6个元素

阵列。


-kondal









kondal写道:


krish写道:


int main()

{


int i,j;

int k [] = {1,2,3,4 ,5};

k [5] = 50;

printf("%d%d",i,j);

}


这个程序编译正常,结果是-858993460 50

我无法找到为什么打印上述值。请求帮助

就此而言。



嘿,索引从0开始。所以数组中有5个元素

从0到4开始。所以k [5 ]将是阵列之外的第6个元素

阵列。


-kondal



这是理解的。但是,为什么j在这里打印价值50所有时间或你所分配的价值。


< blockquote> krish说:


kondal写道:


> krish写道:
< blockquote class =post_quotes>
int main()

{


int i,j;

int k [] = {1,2,3,4,5};

k [5] = 50;

printf("%d%d",i, j);

}


这个程序编译正常,结果是-858993460 50

我无法找到原因这是打印上面的值。请求帮助

就此而言。


嘿,索引从0开始。所以你在数组中有5个元素
从0到4开始。所以k [5]将是界限之外的第6个元素阵列的数据。

-kondal



这是明白的。但是j怎么来这里打印值50

您分配的时间或价值。



你期望j有什么价值?


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)


int main()
{

int i,j;
int k[]={1,2,3,4,5};
k[5]=50;
printf("%d %d",i,j);
}

This program is compiling fine and the result is -858993460 50
I am unable to find why this is printing the above value. Request help
on this

解决方案


krish wrote:

int main()
{

int i,j;
int k[]={1,2,3,4,5};
k[5]=50;
printf("%d %d",i,j);
}

This program is compiling fine and the result is -858993460 50
I am unable to find why this is printing the above value. Request help
on this.

Hey, the indexing starts from 0. So you have 5 elements in the array
starting from 0 to 4. So k[5] would be 6th element outside the bounds
of the array.

-kondal



kondal wrote:

krish wrote:

int main()
{

int i,j;
int k[]={1,2,3,4,5};
k[5]=50;
printf("%d %d",i,j);
}

This program is compiling fine and the result is -858993460 50
I am unable to find why this is printing the above value. Request help
on this.


Hey, the indexing starts from 0. So you have 5 elements in the array
starting from 0 to 4. So k[5] would be 6th element outside the bounds
of the array.

-kondal

That is understood .But how come j is printing the value 50 here all
the time or what ever value you are assigning.


krish said:

kondal wrote:

>krish wrote:

int main()
{

int i,j;
int k[]={1,2,3,4,5};
k[5]=50;
printf("%d %d",i,j);
}

This program is compiling fine and the result is -858993460 50
I am unable to find why this is printing the above value. Request help
on this.


Hey, the indexing starts from 0. So you have 5 elements in the array
starting from 0 to 4. So k[5] would be 6th element outside the bounds
of the array.

-kondal


That is understood .But how come j is printing the value 50 here all
the time or what ever value you are assigning.

What value did you expect j to have?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


这篇关于数组超出界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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