Created
March 19, 2014 12:07
-
-
Save keikoro/9640325 to your computer and use it in GitHub Desktop.
C - return multiple (int) values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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