HP C A.06.05 Reference Manual

Statements
return
Chapter 6176
Functions can return only a single value directly via the return statement. The return value
can be any type except an array or function. This means that it is possible to return more than
a single value indirectly by passing a pointer to an aggregate type. It is also possible to return
a structure or union directly. HP C implements this by passing the structure or union by
reference if the structure or union is greater than eight bytes.
Example
/* Program name is "return_example".
* This program finds the length of a word that is entered.
*/
#include <stdio.h>
int find_length( char *string )
{
int i;
for (i =0; string[i] != ’\0’; i++);
return i;
}
int main( void )
{
char string[132];
int result;
int again = 1;
char answer;
printf( "This program finds the length of any word you ");
printf( "enter.\n" );
do
{
printf( "Enter the word: ");
fflush(stdin);
gets( string );
result = find_length( string );
printf( "This word contains %d characters. \n", result);
printf("Again? ");
scanf("%c", &answer);
} while (answer == ’Y’ || answer == ’y’);
}
If you execute this program, you get the following output: