Dr. Sorin Draghici
Functions
General form: expression1 ? expression2 : expression3
If expression1 evaluates at a true value (non-zero), expression2 will be evaluated and its value will be the value of the whole expression. If expression1 evaluates at a false value (zero), expression3 will be evaluated and its value will be the value of the whole expression.
Example: y = (a>b) ? a : b ;
What does this do ?
int result ;
result = x + y ;
return( result ) ;
}
The declaration specifies the name, the parameters (and their types) and the return value. It does not specify what the function does.
The definition specifies everything about the function (name, parameters with their types, return value and what the function does).
When we want to use a function, we 'call' it using its name. The parameters given when we call the function is what the function will use in its computation.
Actual arguments are the actual values we want to process. The compiler checks if the actual arguments are indeed of the type declared for the formal arguments.
int myfunc ( void )
means that the function takes no arguments
Declaring a function like this:
int myfunc ( )
means that we don't know the arguments
The difference is similar to the difference between saying "I don't know what it is in that bag" and "That bag is empty" (i.e. I do know that the bag contains nothing).
Another example
void swap (double x, double y)
{ double temp ;
temp = x ;
x = y ;
y = temp ;
}
void main ( void )
{
double a = 3. , b = 4. ;
printf("a = %lf, b = %lf \n", a, b ) ;
swap( a, b) ;
printf("a = %lf, b = %lf \n", a, b ) ;
}
Let us trace the execution of this program.
As any other variable, a pointer has:

void swap (double *x, double *y ) ;
void swap (double *x, double *y)
void main ( void )
{ double temp ;
temp = *x ;
*x = *y ;
*y = temp ;
}
{
double a = 3. , b = 4. ;
printf("a = %lf, b = %lf \n", a, b ) ;
swap( &a, &b) ;
printf("a = %lf, b = %lf \n", a, b ) ;
}
Summary