tag:blogger.com,1999:blog-6289695796997559266.post7243786066206766590..comments2022-03-18T05:02:51.033-07:00Comments on The C++ blog: I know this code does not work as expected100rabh™http://www.blogger.com/profile/08213344486463590285noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-6289695796997559266.post-38110915754562866772010-04-19T21:29:45.457-07:002010-04-19T21:29:45.457-07:00Or you can just simply put 'i' inside the ...Or you can just simply put 'i' inside the scope of the for loop<br /><br />// int i;<br /> int array[4];<br /> for(int i = 0; i <= 20000; i++) <br /> {<br /> array[i] = 0;<br /> printf("%d passed \n",i);<br /> }Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6289695796997559266.post-63174940694000002122008-12-09T00:41:00.000-08:002008-12-09T00:41:00.000-08:00You can avoid infinite loops by allocating memory ...You can avoid infinite loops by allocating memory for your arrays with <I>malloc()</I> :-)<BR/><BR/># include <stdio.h><BR/># include <stdlib.h><BR/><BR/> int main() {<BR/> <BR/> int i;<BR/> int *array = (int *)malloc(<B>4</B> * sizeof(i));<BR/> for(i = 0; i <= <B>20000</B>; i++) {<BR/> array[i] = 0;<BR/> printf("%d passed \n",i);<BR/> }<BR/><BR/> return 0;<BR/> } // main()ern0https://www.blogger.com/profile/10560853500686689739noreply@blogger.com