Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Why is the custom plastic function in C language still valid without a return value?
Why is the custom plastic function in C language still valid without a return value?
In C, in general, we can only return a value from a function. But in some cases, we need to return multiple values from a function, and using arrays or pointers can accomplish this task well. Here's one

For example, this program takes an integer array as a parameter and returns the sum and product of the array elements to the calling function. Here is the C code, which is very common. The following is the implementation technology:

1.

# Including

2.

# Including

3.int*

Pool(int array[],int size)

4.

{

5.

int * x;

6.

int I = 0;

7.

Internationalorganizations (same as international organizations)

a[2]={0, 1 };

8.

for(I = 0; I

9.

{

10.

a[0]+= array[I];

//Stores the sum of array element values.

1 1.

a[ 1]* = array[I];

//Store the product of array element values.

12.

}

13.//

Assign the base address of the array to an integer pointer.

14.

x = & ampa[0];

15.//

Returns the entire array.

16.

Returns x;

17.}

18.

19.int main()

20.{

2 1. (same as Internationalorganizations) International organizations

a[]={ 1,2,3,4 };

22. Internationalorganizations (with international organizations)

* c; C = pool (a, 4);

23.

printf("Sum = %d\nProduct = %d\n ",c[0],c[ 1]);

24.

getch();

25.

Returns 0;

26.}

In this way, we know how to use arrays and pointers to return multiple values from C functions. You will find this technique very useful in many situations.