Home > Back-end >  Small white to ask: C prompt interrupted by signal 11: sigsegv
Small white to ask: C prompt interrupted by signal 11: sigsegv

Time:03-22

Zero base turned white... Ligatures both programs appear this problem, searched the discovery should be segmentation fault but still can not find out the problem, one of the function code is as follows:

#include
using namespace std;

Const int N=6;
Int * findMissing (int arr [], int n, int& ResArrSize);
Arr void printArray (int * and an int arrSize);
Int main () {
Int arr [N]={3, 1, 3, 0, 6, 4};
Int resArrSize;
Int * missingArr=NULL;

MissingArr=findMissing (arr, N, resArrSize);
cout <"The logical size of The new array is" & lt; PrintArray (missingArr resArrSize);

The delete [] missingArr;
MissingArr=NULL;

return 0;
}

Int * findMissing (int arr [], int n, int& ResArrSize) {
int i, j;
Int missingArrSize;

Int * range=new int [n + 1);
for (i=0; i <(n + 1); I++) {
Range [I]=I;
}

MissingArrSize=n + 1;
for (i=0; i <(n + 1); I++) {
If (range [arr [I]].=1) {
Range [arr [I]]=1;
MissingArrSize -;
}
}

J=0;
Int * missingArr=new int [missingArrSize];
for (i=0; i <(n + 1); I++) {
If (range [I]!=1) {
MissingArr [j]=range [I];
J++;
}
}

The delete [] range;
The range=NULL;

ResArrSize=missingArrSize;

Return missingArr;
}

Arr void printArray (int * and an int arrSize) {
int i;

for (i=0; i cout }

Thank you very much!!!!!

CodePudding user response:

Crossing the line
If (range [arr [I]].=1) {//this sentence, because I up to 6, the arr is the most effective element six, so arr [6] is invalid element, so the cross-border

CodePudding user response:

Wow, that's it! Thank you very much.
  • Related