Q:

Understanding functions and pointers in C

This is a very simple question but what does the following function prototype mean?
int square( int y, size_t* x )
what dose the size_t*  mean?  I know size_t is a data type (int >=0).  But how do I read the * attached to it?  Is it a pointer to the memory location for x?  In general I'm having trouble with this stuff, and if anybody could provide a handy reference, I'd appreciate it.

Thanks everybody. I understand what a pointer is, but I guess I have a hard hard time understanding the relationship between pointers and functions. When I see a function prototype defined as int sq(int x, int y), then it is perfectly clear to me what is going on. However, when I see something like int sq( int x, int* y), then I cannot--for the life of me--understand what the second parameter really means. On some level I understand it means "passing a pointer" but I don't understand things well enough to manipulate it on my own.

A:

How about a tutorial on understanding pointers?
In this case however, the pointer is probably used to modify/return the value. In C, there are two basic mechanisms in which a function can return a value (please forgive the dumb example):
It can return the value directly:
float square_root( float x )
{
    if ( x >= 0 )
        return sqrt( x );
    return 0;
}

Or it can return by a pointer:
int square_root( float x, float* result )
{
    if ( x >= 0 )
    {
        *result = sqrt( result );
        return 1;
    }
    return 0;
}

The first one is called:
float a = square_root( 12.0 );

... while the latter:
float b;
square_root( 12.00, &b );

Note that the latter example will also allow you to check whether the value returned was real -- this mechanism is widely used in C libraries, where the return value of a function usually denotes success (or the lack of it) while the values themselves are returned via parameters.
Hence with the latter you could write:
float sqresult;
if ( !square_root( myvar, &sqresult ) )
{
   // signal error
}  
else
{ 
   // value is good, continue using sqresult!
}

