Skip to content

Instantly share code, notes, and snippets.

@keikoro
Created March 19, 2014 12:07
Show Gist options
  • Save keikoro/9640325 to your computer and use it in GitHub Desktop.
Save keikoro/9640325 to your computer and use it in GitHub Desktop.
C - return multiple (int) values
/* Output multiple (integer) values
defined in a function
to main function.
Based on solution #2 of accepted answer in this Stack Overflow thread:
https://stackoverflow.com/questions/2620146/
how-do-i-return-multiple-values-from-a-function-in-c
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
void getValues(int* a, int* b) {
assert(a);
assert(b);
*a = 1;
*b = 2;
}
int main() {
int a, b;
getValues(&a, &b);
printf("a is %d\nb is %d\n", a, b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment