1. any problem if i dynamically allocate memory and use only a small part of it?
2. can i free the dynamic memory after each time the function is executed?

1. No
2. Yes, providing you reallocate the memory before attempting to use it. .

is the position of 'free a' in pgm correct?

function(variables)
{
a=malloc(...);
....
return a;
free a; //is this the correct position to free a?
}

No -- reverse the order of lines 5 and 6. As it is, line 6 will never get executed because the function exits on line 5.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.