In grading programming assignments from previous versions of this course involving writing C/C++ code, I have compiled a list of comments when I graded and reviewed the submitted code.
int tempWindow[size];instead of
int* tempWindow = new int[size];
int i, j, index; for (i = 0; i < MAX_INDEX; i++) { for (j = 0; j < MAX_INDEX; j++) { index = i + j; } }would be compiled into more efficient code as
int i; for (i = 0; i < MAX_INDEX; i++) { int j; for (j = 0; j < MAX_INDEX; j++) { int index = i + j; } }
if ( (window_size%2) == 0 ) window_size++;
delete arrayName;but instead do
delete [] arrayName;Also, as a precaution against freeing the same memory multiple times, set a pointer to zero after it has been deallocated.