0
How to return more than one integer from a function in C?
I want to return more than one integer from a function that is called from main, also in which series will I obtain those numbers. Can you please explain
4 Answers
+ 3
1) You can make use of a bigger data structure like array or make a custom data type ( maybe a struct of all those integers ) and return one variable of that type.
2) ( as already suggested by Jay Matthews ) Instead of passing the values of the variables, you can pass the addresses to the function so that function may directly alter the original variables.
+ 2
You can use dynamically allocated array or you can use struct.
And you can also pass pointer to the function so that it can modify your variables in main function
0
You can easily do it via command line arguments
0
int* fun(){}
Signature expects a pointer to int. Int can be an array (multiple ints)