Home > Software engineering >  MFC C pointer reads the exception
MFC C pointer reads the exception

Time:10-08

 int the Find (carsList cars, LinkQueueCar que, cstrings e) {
CarsList p=cars - & gt; Next;
QueueNode * q=que. Front - & gt; Next;
CString str;
While (p!=NULL) {
Cstrings STR (p - & gt; CarNumber);
If (e==STR)
return 1;
P=p - & gt; Next;
STR. Empty ();
}
While (q!=NULL) {
Cstrings STR (q - & gt; CarNumber);
If (e==STR)
return 1;
Q=q - & gt; Next;
STR. Empty ();
}
return 0;
}




I the while loop is in the case of p is not empty into the loop body, why have this kind of phenomenon of null pointer?

CodePudding user response:

Because next and not initialized to NULL, so when you use for the first time, he is not NULL, a wild pointer

CodePudding user response:

0 XCD is allocated memory but no space of initialization, apply for a new node first initialized after



CodePudding user response:

Q=que. Front - & gt; Next;//=0?

CodePudding user response:

CarsList p=NULL;
P=cars - & gt; Next;
So to write better
  • Related