ADVERTISEMENT
ADVERTISEMENT

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 

ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.