RE: [Dev-C++] Correct use of pointers II
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <iv...@em...> - 2003-03-15 23:17:29
|
-----------------------Original Message-----------------------
>From: Andr=E9 Mac=E1rio Barros [mailto:and...@su...]
>To: Dev-Cpp-Users [mailto:dev...@li...]
>Date: 16/3/2003 2:08:00 =F0=EC
>Subject: [Dev-C++] Correct use of pointers II
>
>Gentlemen,
>
> 1. In a generic point of view, can I use this code? (Y/N)
Yes, but the malloc() is in bad style C.
> 2. Would it be technically correct? (Y/N)
Yes.
>
>#include <stdlib.h>
>
>int main()
>{
> int a=3D3, b=3D2, *p;
>
> p=3D(int *)malloc(1*sizeof(int));
p=3Dmalloc(sizeof(int));
or
p=3Dmalloc(sizeof(*p));
> *p =3D a + b;
>
> /* .... */
>
> free(p);
>}
Ioannis Vranos=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys=20
|