Home > Back-end >  Why but I think the value of the output array output address? B why 0?
Why but I think the value of the output array output address? B why 0?

Time:03-29

want to input matrix, and then print out the matrix, if press 1, then re-enter, press 0, continue to the next step, then the 2 d array num in one-dimensional array b, bubble sort of b, the output of the specified sequence element,
#include
# include "stdio.h"
using namespace std;

Void firststep ()
{
//input matrix
Int hang=0, lie=0, hangam=0, lieam=0;
Cout & lt; <"Please input rows and columns of the matrix (100)" & lt; Cin & gt;> Hangam & gt;> Lieam;

Int num [100] [100].//!
Cout & lt; <"Please input in sequence" & lt; For (int hang=0; Hang & lt; Hangam; Hang++)
{
For (int lie=0; Lie & lt; Lieam; Lie++)
{
Cin & gt;> Num [hang] [lie];
}

}

//print matrix
Cout & lt; <"You input matrix is:" & lt; For (int hang=0; Hang & lt; Hangam; Hang++)
{
For (int lie=0; Lie & lt; Lieam; Lie++)
{
Cout & lt; }
Cout & lt; }

Short press;
Cout & lt; <"If the input is correct, please press 0" & lt; Cin & gt;> Press;
If (press==1)
{
Firststep ();
}
The else {cout & lt; };




Int main ()
{
Int hang=0, lie=0, hangam=0, lieam=0;
Int num [100] [100].
Firststep ();

//input ordinal
Int ordinal=0;
Cout & lt; <"Looking for which large elements & lt;" Cin & gt;> The ordinal.

Cout//this time why the output is the address, not a value

//into a one dimensional array
Int [10000] b={0};
Int * p=b;
Int len=hangam * lieam;
For (int I=0; I & lt; Hangam; I++)
{
For (int j=0; J & lt; Lieam; J++)
{
* (p + (I + j * lieam))=num [I] [j];
}
}


//
For (int k=0; K & lt; Len - 1; K++)
{
For (int h=0; H & lt; Len - k - 1; H++)
{
If (b [h] {
Int temp=b [h];
B=b [h] [h + 1);
B [h + 1)=temp;
}
}
}

Cout & lt; <"The first" & lt; //here 0 is the output of the value of b why? How to change?
return 0;
};

CodePudding user response:

Oh, I realized, after the local variable in a function to use will be released, so this time is not the value of num, b
  • Related