Advanced C topics – Part2
March 15, 2010 Leave a comment
Some of the things which could not fit into the previous post will be explained here.
In the previous post related to advanced C topics we were discussing about comparaison between arrays and pointers, how is an array of characters different than a pointer to an array of characters, how can arrays be passed as parameters and how you can avoid being tricked by the way bi-dimensional arrays are passed as parameters. In this post I will try to outline how can an array be returned as a value from a function and what’s the use of pointers to functions.
Let me start with the first item: how to return arrays from functions. Just have a look at the following code snippet:
char* function (int n)
{
char buffer[200];
….
return buffer;
}
