Application crash
-
Hi, Please look into the code and reply my question char *ptrChar; ptrChar= new ch; *ptrChar = 'c'; '' '' some logic here '' ptrChar = NULL; when I tried to use delete ptrChar,application is getting crashed but if I assign it to NULL application is not crashing , is this correct way of coding Can anyone please explain Thanks Uday
-
Hi, Please look into the code and reply my question char *ptrChar; ptrChar= new ch; *ptrChar = 'c'; '' '' some logic here '' ptrChar = NULL; when I tried to use delete ptrChar,application is getting crashed but if I assign it to NULL application is not crashing , is this correct way of coding Can anyone please explain Thanks Uday
'ch' is an unspecified type. Please repost what your code really looks like.
-
'ch' is an unspecified type. Please repost what your code really looks like.
Sorry, Char ch;
-
Hi, Please look into the code and reply my question char *ptrChar; ptrChar= new ch; *ptrChar = 'c'; '' '' some logic here '' ptrChar = NULL; when I tried to use delete ptrChar,application is getting crashed but if I assign it to NULL application is not crashing , is this correct way of coding Can anyone please explain Thanks Uday
use
ptrChar = new char
thendelete ptrChar
You should alwaysdelete
what you create withnew
. Setting ptrChar to NULL after deleting is good practice if you may use ptrChar later.Jason Henderson
quasi-homepage
articles
"Like it or not, I'm right!" -
Hi, Please look into the code and reply my question char *ptrChar; ptrChar= new ch; *ptrChar = 'c'; '' '' some logic here '' ptrChar = NULL; when I tried to use delete ptrChar,application is getting crashed but if I assign it to NULL application is not crashing , is this correct way of coding Can anyone please explain Thanks Uday
hi, Assigning a pointer to NULL does not actually free the allocated memory. Your memory should have been allocated by using "new char". ch is not any type here. I presume it should have been "char". One very nice thing about delete is that even if the pointer = NULL, ur app _won't_ crash. I just replace that new ch with "new char". and then delete ptrChar; Regards, Sharad Ganesh
-
hi, Assigning a pointer to NULL does not actually free the allocated memory. Your memory should have been allocated by using "new char". ch is not any type here. I presume it should have been "char". One very nice thing about delete is that even if the pointer = NULL, ur app _won't_ crash. I just replace that new ch with "new char". and then delete ptrChar; Regards, Sharad Ganesh
hi, memory is allocated using new but still when I am trying to delete, it is getting crashed Uday
-
Sorry, Char ch;
you should do this:
char *ptrChar;
ptrChar= new char;
*ptrChar = 'c';
''
'' some logic here
''
delete ptrchar;Best regards, Alexandru Savescu
-
hi, memory is allocated using new but still when I am trying to delete, it is getting crashed Uday
hi, Did u check up on the corrected code i posted ? There was a corection "new char". Rgds, Sharad