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

30th Oct 2021, 3:27 PM
Ruchika Sehgal
Ruchika Sehgal - avatar
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.
30th Oct 2021, 4:25 PM
Arsenic
Arsenic - avatar
+ 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
30th Oct 2021, 9:38 PM
🌀 Shail Murtaza ŰŽŰčیل Ù…Ű±ŰȘŰ¶ÛŒÙ°
🌀 Shail Murtaza ŰŽŰčیل Ù…Ű±ŰȘŰ¶ÛŒÙ° - avatar
0
You can easily do it via command line arguments
30th Oct 2021, 5:40 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
int* fun(){} Signature expects a pointer to int. Int can be an array (multiple ints)
30th Oct 2021, 7:19 PM
William Owens
William Owens - avatar