If I have a function that produces a result int
and a result string
, how do I return them both from a function?
As far as I can tell I can
Create a struct and set two values inside and return the struct variable.
struct result {
int a;
char *string;
}
You have to allocate space for the char *
in your program.
By passing parameters by reference to function.
Examples:
void incInt(int *y)
{
(*y)++; // Increase the value of 'x', in main, by one.
}
Also by using global variables but it is not recommended.
Example:
int a=0;
void main(void)
{
//Anything you want to code.
}