RE: [Dev-C++] Why thisC example don't presents the correct result ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: P.D. v. Z. <pd...@xs...> - 2003-12-11 14:38:32
|
Because your code is wrong (aside from the fact that you sent this
(stupidly) as an HTML mail... don't do that!).
=20
I believe you repeatedly tried to ask this very same question on the =
forum
(and thereby annoying the moderators).
Your third v element (v[2]) isn't initialized to anything, so it can =
contain
any arbitrary value. Then in your for loop you use the null character to
check if you've reached the end of the array (which is wrong as well, =
simply
use an int, like 0 (even though they are actually the same value)). =
Because
the third element of v will contain garbage, your program will loop =
until it
finally touches some memory that it _really_ shouldn't, and will
subsequently crash.
This code will work:
#include <stdio.h>
int main()
{
int v[3], i;
v[0] =3D 10;
v[1] =3D 200;
v[2] =3D 0;
=09
i =3D 0;
while (v[i] !=3D 0)
{
printf("%d\n", v[i]);
i++;
}
}
Another thing: By saying "this does work in other compilers" (or =
utterings
of the same sort) you imply that this compiler is at fault because it =
won't
compile your perfect code, because you know it's perfect, because other
compilers do make it work. The compiler Dev-C++ uses is the MinGW port =
of
GCC. GCC is about the most standards-compliant compiler you'll find, so =
you
can safely assume that it's the other compilers that are at fault, not =
GCC.
Regards,
Paul
________________________________
From: dev...@li...
[mailto:dev...@li...] On Behalf Of
hu...@cl...
Sent: Thursday, December 11, 2003 3:21 PM
To: dev...@li...
Subject: [Dev-C++] Why thisC example don't presents the correct result ?
Hi all,=20
in others compilers this is the result :=20
10=20
200=20
of this program :=20
#include=20
main <http://pcp.clix.pt/images/canais/webmail2/smile/kiss.gif>=20
{=20
int v[3],i;=20
v[0]=3D10;=20
v[1]=3D200;=20
i=3D0;=20
while(v[i]!=3D'\0')=20
{=20
printf("%d\n",v[i]);=20
i++;=20
}=20
}=20
in dev-c++compiler i have the this result :=20
10=20
200=20
2293664=20
4198592=20
4210688=20
4210692=20
2293664=20
4198757=20
1=20
4138088=20
4139640=20
4198553=20
Why ?????=20
Thanks.=20
--
Hugo Dias
=20
Clix Rapidix - Aumente at=E9 6X a velocidade da sua Internet Adira em
http://acesso.clix.pt e comece logo a navegar
------------------------------------------------------- This SF.net =
email
is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just
sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn
everything from the bash shell to sys admin. Click now!
http://ads.osdn.com/?ad_id=3D1278&alloc_id=3D3371&op=3Dclick
_______________________________________________ Dev-cpp-users mailing =
list
Dev...@li... TO UNSUBSCRIBE:
http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users=20
|