according to ur prob, i made the simple program:
#include<iostream.h>
void main()
{
int n=30,p;
for(p=0;p<=n;p++)
{
cout<<" "<<p;
}
getch();
}
the output... :  0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 
24 25 26 27 28 29 30
this means value of p is 30.... 
so p isnt stopping at 29..
can u plz explain ur questn... or check my answer..

--- On Tue, 11/11/08, Brett McCoy <[EMAIL PROTECTED]> wrote:

From: Brett McCoy <[EMAIL PROTECTED]>
Subject: Re: [c-prog] Infinite loop
To: [email protected]
Date: Tuesday, November 11, 2008, 7:30 PM






On Tue, Nov 11, 2008 at 1:23 AM, satish <[EMAIL PROTECTED] com> wrote:

> ok so while running the output , it seems that p never reaches 30 , not
> sure why !
>
> so giving the for loop as any of the following works fine, ...
>
> for (p=0;p<n;p++ )
>
> or
>
> for (p=0;p<=n-1; p++)
>
> ,
> but what i am not able to understand is when for(p=0;p<=n; p++) ,
> why is p stopping at p=29 ??
>
> i don find anything wrong in the program though !

Because your array goes from 0 ... 29 but your loop goes from 1 ...
30. The array has no element 30 so if you write to c[30] you have an
array bounds error.

-- Brett
------------ --------- --------- --------- --------- --------- -
"In the rhythm of music a secret is hidden;
If I were to divulge it, it would overturn the world."
-- Jelaleddin Rumi
 














      

[Non-text portions of this message have been removed]

Reply via email to