|
From: <and...@su...> - 2003-03-14 00:46:21
|
Gentlemen,
Even in the Ritchie´s books sometimes I fount .C codes using "wild
pointers" or something
like:
****************
void main()
{
int *p, a, b;
a=2;
b=3;
*p = 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=malloc(1*sizeof(int));
a=2;
b=3;
*p = a + b;
...
free(p);
}
******************
1. It´s not necessary, but is it tecnically correct?
2. Is there any point, where the previous memory allocation is mandatory?
Thanks
Andre
|