Home > Back-end >  Turn bosses...
Turn bosses...

Time:09-23

Input 10 integers, including the first will be the smallest and the count of exchange, the greatest number with the last element, write three functions: (1) input 10 integers (2) for processing (3) output number 10,

Editor shows 0 warning0error, but in the end but cannot run shows that there is a problem,,, where is make wrong?
# include
Void inp (int * p);
Void change (int * p);
Void oup (int * p);
The main ()
{int a [10], * p=a;
Inp (p);
Change (p);
Oup (p);
}

Void inp (int * p)
{int I;
Printf (" do input 10 integers: ");
for(i=0; I<10; I++)
The scanf (" % d ", * (p + I));
}

Void change (int * p)
Min {int temp, * and * Max, n.
Min=p;
For (n=1; N<10; N++)
{if (* min> * (p + n))
Min=p + n.
}
Temp=* p;
P=min;
* min=temp;
Max=p;
For (n=1; N<10; N++)
{if (* max<* (p + n))
Max=p + n.
}
Temp=* (p + 9);
* (p + 9)=* Max;
* Max=temp;
}

Void oup (int * p)
{int I;
for(i=0; I<10; I++)
Printf (" % d ", * (p + I));
}

CodePudding user response:

Using pointer must finish? If not complete, with an array you this pointer exchange there should be a mistake

CodePudding user response:

 # include 
Void inp (int * p);
Void change (int * p);
Void oup (int * p);
Int main ()
{
Int a [10], * p=a;
Inp (p);
Change (p);
Oup (p);
return 0;
}
Void inp (int * p)
{
int i;
Printf (" do input 10 integers: \ n ");
for (i=0; I<10; I++)
The scanf (" % d ", (p + I));//-- -- -- -- -- -- -- -- -- -- - * (p + I) to (p + I) -- -- -- -- -- -- -- -- -- -- -- -- --
}

Void change (int * p)
{
Int temp, min, Max, n;
Min=p;
For (n=1; N<10; N++)
{
If (* min> * (p + n))
Min=p + n.
}
Temp=* p;
* p=* min;//-- -- -- -- -- -- -- -- -- p=min min to * p=* -- -- -- -- -- -- -- -- --
* min=temp;
Max=p;
For (n=1; N<10; N++)
{
If (* max<* (p + n))
Max=p + n.
}
Temp=* (p + 9);
* (p + 9)=* Max;
* Max=temp;
}

Void oup (int * p)
{
int i;
for (i=0; I<10; I++)
Printf (" % d ", * (p + I));//-- -- -- -- -- -- -- -- -- -- add a space after % d -- -- -- -- -- -- -- -- -- -- -- --
}

C + + environment debugging VS2015

CodePudding user response:

Ok!
Can you bother to ask you why not add when p=a (array) *, are not added when the scanf *, * p=* min, however, when the printf to add *,,,

CodePudding user response:

The
reference 3 floor response:
ok!
Can you bother to ask you why not add when p=a (array) *, are not added when the scanf *, * p=* min, however, want to add *, printf,,

The nature of the knowledge of the good under the pointer, pointer is pointing to an address, give it an address pointer assignment to nature, is the array of arrays of delegates space first address

The scanf changes the contents of the address space that is to change the address so I need the content of the incoming variable address
* * * p=min here is value, also has been to find the address, but want to change a value to this address, so the corresponding behind also want to assign a value
Printf the use depends, you can try to look with output with no distinction, variables, level of pointer, the secondary pointer is to try, different content, integer, character, string, basically try understand it
I don't know that I can understand, may speak a little discrepancy with nature, after all, your own organization, suggest you go to the next * pointer on different usage, look at this a few function prototypes, good understand some
  • Related