Home > Back-end >  C ask bosses
C ask bosses

Time:09-23

Int * Max (int a [], int n)
{
Int * p=& amp; A [0], I;
for(i=0; I{
If (* pP=& amp; A, [I].
}
Return * p;
}
Int * min (int a [], int n)
{
Int * p=& amp; A [0], I;
for(i=0; I{
If (* p> A [I])
P=& amp; A, [I].
}
Return * p;
}
Int ave (int a [], int n)
{
Int I, sum=0;
for(i=0; I{
The sum +=a [I];
}
Return the sum/n;
}
#include
Int main ()
{
,2,3,4,5,6,7,8,9,10 int [10] b={1}, n=10, big, small, pingjun;
Big=Max (b [0], n);
Small=min (b [0], n);
Pingjun=ave (b [0], n);
Printf (" % d % d % d ", big, small, pingjun);
return 0;
}
Emmm displayed in the Max and min is a problem with the two function and is the main function of Max and min input has a problem,

CodePudding user response:

You just said there is a problem, do not say what specific phenomenon? Compile or run issue?

CodePudding user response:

You define the parameter is an array of addresses, the incoming value is
Int * Max (int a [], int n) int a [] to pass a first address ()
Big=Max (b [0], n);
Small=min (b [0], n);
* p=a, is p take a first address, it is not necessary to & a [0]; More easily mistaken

CodePudding user response:

And you have a problem the return value is
Int * min (int a [], int n) you define the type of the return value is a pointer, but you return values, have a good look at, suggested that the pointer * has different meanings in different places

CodePudding user response:

//int * Max (int a [], int n) 
Int Max (int a [], int n)
{
Int * p=& amp; A [0], I;
for(i=0; I{
If (* p
P=& amp; A, [I].
}
Return * p;
}

//int * min (int a [], int n)
Int min (int a [], int n)
{
Int * p=& amp; A [0], I;
for(i=0; I{
If (* p> A [I])
P=& amp; A, [I].
}
Return * p;
}
Int ave (int a [], int n)
{
Int I, sum=0;
for(i=0; I{
The sum +=a [I];
}
Return the sum/n;
}
//# include & lt; stdio.h>
Int main ()
{
,2,3,4,5,6,7,8,9,10 int [10] b={1}, n=10, big, small, pingjun;
//big=Max (b [0], n);
Big=Max (b, n);
//small=min (b [0], n);
Small=min (a, b, n);
//pingjun=ave (b [0], n);
Pingjun=ave (b, n);
Printf (" % d % d % d \ n ", big, small, pingjun);
return 0;
}

For your reference ~

Big=Max (& amp; B [0], n);
Also can such,

CodePudding user response:

refer to the second floor qq_1457346882 response:
you to define the parameter is an array of addresses, the incoming value is
Int * Max (int a [], int n) int a [] to pass a first address ()
Big=Max (b [0], n);
Small=min (b [0], n);
* p=a, is p take a first address, it is not necessary to & a [0]; More easily mistaken

If is a [1] address is & amp; A [1]

CodePudding user response:

reference 5 floor qq_47279096 reply:
Quote: refer to the second floor qq_1457346882 response:
you to define the parameter is an array of addresses, the incoming value is
Int * Max (int a [], int n) int a [] to pass a first address ()
Big=Max (b [0], n);
Small=min (b [0], n);
* p=a, is p take a first address, it is not necessary to & a [0]; More easily mistaken

If is a [1] address is & amp; A [1]

If you take a [1] see initialization or what you are, if is initialized & amp; A [1] can, if not, what was to come up with a program p address later want to find a p [1] address, p + 1 line directly, [1] can be seen as a * (a + 1), an array of operation is the nature of the movement of the pointer, p=& amp; A [0]=& gt; P=& amp; * (a + 0) value * address & amp; Offset, p=a + 0;=> P=a; P=a + 1 + 1; A + 1 can be expressed as & * (a + 1)=& gt; & A, [1]. The pointer is very flexible and easy to wrong, want to have a good understanding
  • Related