c code in an infinite loop due to fencepost e

December 5, 2010 at 23:36:42
Specs: Windows 7, i5/6GB
C code with a fencepost error:
int a[10];
int i;
for (i = 0; i <= 10; i++) {
a[i] = 0;
}
this code is bugy and on some C implementations it can goes into infinite loop.
Can anyone tell me the reason for this?

See More: c code in an infinite loop due to fencepost e

Report •

#1
December 6, 2010 at 03:45:10
for( i = 0; i <= 10; i++)
it should be for( i = 0; i <= (10 - 1); i++) or for( i = 0; i <= 9; i++).

a[10] is going to give access violation. i don't see more errors.

.....................................
_Adnan_


Report •

#2
December 6, 2010 at 03:47:00
for ( i = 0; i < 10; i++ )

.....................................
_Adnan_


Report •

#3
December 6, 2010 at 20:21:34
@lander01 : u r not suppose to discuss assignment questions like this on internet. This is against honesty policy which u have signed.

Report •
Related Solutions


Ask Question