Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Return values and result parameters

&pagelevel(4)&pagelevel

Return value pointer

<type> *funct(...)

Many functions that return a pointer write their result to an internal C data area that is overwritten whenever the function is called. Since this is a common source of errors, it is mentioned explicitly for all functions of the data type pointer.

Return value void *

void * funct(...)

If the value of a void * function is assigned to a pointer variable, the type should be converted explicitly using the cast operator. If the call is made from within a C++ source, explicit type conversion is mandatory.

Example

long *long_ptr;
.
.
long_ptr  (long *)calloc(20, sizeof(long));

Return value int

int funct();

Character-processing functions have a return value of type int, since EOF (=-1) is a possible return value for such functions. If the function returns a value of type char, an error occurs in a program.

Result parameter pointer

<type1> funct(<typ2> *variable)

Result parameters are variables whose contents are changed by the function, i.e. the function stores a result in such variables. Result parameters are defined without the const suffix.

The address, i.e. a pointer, must always be passed as the argument. Furthermore, the memory for the result must be allocated explicitly before calling the function. Since this is often overlooked, reminders are provided in the pertinent function descriptions.

Examples

struct timeb tp;    /* structure */
ftime(&tp);
char erg;           /* char variable */
scanf("%c", &erg);
char array[10];     /* string variable */
scanf("%s", array);