C - Return Multiple Values from Function using C Program.
IncludeHelp
02 August 2016
In this code snippet, we will learn how to implement a function that will return multiple values using c program. Since function can return only one value but using passing variables as pointer we can initialize them from function, hence we can get multiple values from the function.
C Code Snippet - Return Multiple Values through Function using C Program
//C - Return Multiple Values from Function using C Program.
#include <stdio.h>
//function to return multiple values from function
//Author: www.includehelp.com
void returnMulValues(int *x, int *y, char *c){
*x=10;
*y=20;
*c='x';
}
int main(){
int intValue1,intValue2;
char charValue;
//initialize values from string
returnMulValues(&intValue1, &intValue2, &charValue);
printf("Value of intValue1: %d\n",intValue1);
printf("Value of intValue2: %d\n",intValue2);
printf("Value of charValue: %c\n",charValue);
return 0;
}
Value of intValue1: 10
Value of intValue2: 20
Value of charValue: x