I have allocated a array like
double a[1024];
We know that a 1-D array just like an 1-D pointer.
You don't know that. You may think that, but you're mistaken. (You're
not alone in this, though; it's a very widely propagated myth.) An array
is really nothing like a pointer, it just mimics one in some, often-
encountered, circumstances. Behind the scenes, they're really quite
dissimilar.
For example, here you've asked for memory for 1024 doubles. You're
either getting it or not; you haven't got any error recovery. You cannot
make this memory "point to" another address. The thing is where it is.
Had you done this:
double a*;
a=malloc(1024 * sizeof *a);
you'd have asked for two bits of memory: one for the pointer itself, and
one for the 1024 doubles. The first bit is much like the array: it is a
single, unmovable object. The second bit, though, is more flexible. If
there isn't enough memory for 1024 doubles, you can recover from this,
because a is now a null pointer and you can check for that. If you want
more, you can realloc(). If you want a to point at another block of
doubles, you can point it there. It's much more flexible; but that
flexibility comes at the price of having to control it.
So I wonder that should I release the memory of the array myself like
free(a);
Certainly not. You only do that with pointers you got from any of the
*alloc() functions.
Richard