What's the advantage of malloc?
What is the advantage of allocating a memory for some data. Instead we
could use an array of them.
Like
int *lis;
lis = (int*) malloc ( sizeof( int ) * n );
/* Initialize LIS values for all indexes */
for ( i = 0; i < n; i++ )
lis[i] = 1;
we could have used an ordinary array.
Well I don't understand exactly how malloc works, what is actually does.
So explaining them would be more beneficial for me.
And suppose we replace sizeof(int) * n with just n in the above code and
then try to store integer values, what problems might i b facing? And is
there a way to print the values stored in the variable directly from the
memory allocated space, for example here it is lis?
No comments:
Post a Comment