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: Glenn W. <gl...@mr...> - 2003-12-11 14:37:18
|
I'm not sure exactly what you are trying to do. Bounds checking in c =
could be done this way but only if you actually initialized all of your =
subscripts. Since v[2] is never initialized you are getting whatever =
value is stored in this memory space which could be anything. Character =
arrays used for strings are the only thing I would know of that would =
store a null in the last position, but even this would only be true if =
you initialized the c string with an actual string instead of =
characters.
=20
char v[3] =3D "AB"; will result in 'A', 'B' and '\0'
char v[3] =3D {'A', 'B'} will result in the 3rd position being =
uninitialized
=20
In short there isn't bounds checking in C and you can't assume that a =
value exists unless you place it in the array yourself. It would be =
safest to keep the size of the array in something like a constant and =
use that for looping through your array.
=20
Sincerely,=20
Glenn Welker=20
Director of Product Development=20
MRH Technology Group=20
-----Original Message-----
From: hu...@cl... [mailto:hu...@cl...]
Sent: Thursday, December 11, 2003 9:21 AM
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
|