Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

Pointer as a return value and result parameter

&pagelevel(3)&pagelevel

Return value pointer

<type> *funct(...)

Some functions that return a pointer write their result to an internal C data area that is overwritten each time this function is called. Because this is a common source of errors, it is explicitly mentioned 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. When calling from within C++ sources, explicit type conversion is mandatory.

Example

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

Result parameter pointer

<type1> funct(<type2> *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 const.

The address, i.e. a pointer, must always be passed as the argument. In addition, you must explicitly provide memory space for the result 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);