RE: [Dev-C++] Correct use of pointers
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Somanathan K. <som...@wi...> - 2003-03-14 06:36:30
|
I couldn't understand how the first one will work(without allocating =
memory
for p). This should crash soon or later.
Somanathan
-----Original Message-----
From: Andr=E9 Mac=E1rio Barros [mailto:and...@su...]=20
Sent: Friday, March 14, 2003 6:16 AM
To: Dev-Cpp-Users
Subject: [Dev-C++] Correct use of pointers
Gentlemen,
Even in the Ritchie=B4s books sometimes I fount .C codes using "wild
pointers" or something
like:
****************
void main()
{
int *p, a, b;
a=3D2;
b=3D3;
*p =3D a + b;
...
}
****************
But... in large programs we can have problems.
Would I be corret, allways, if I use insted a code like:
*********************
#include <stdlib.h> /* or alloc.h */
void main()
{
int *p, a, b;
p=3Dmalloc(1*sizeof(int));
a=3D2;
b=3D3;
*p =3D a + b;
...
free(p);
}
******************
1. It=B4s not necessary, but is it tecnically correct?
2. Is there any point, where the previous memory allocation is =
mandatory?
Thanks
Andre
-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open!=20
Get cracking and register here for some mind boggling fun and=20
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|