Recently I did a C test where I had to complete a code to remove items from a queue, follow the code with the correct answer highlighted:
typedef struct No {
int dado;
struct No *proximo;
};
typedef struct Fila {
struct No *inicio;
struct No *fim;
};
struct Fila *filaDePosts;
int filaRemover(){
struct No* ptr_no = fila->inicio;
int dado;
if (ptr_no != NULL) {
**fila->inicio = ptr_no->proximo;**
**ptr_no->proximo = NULL;**
dado = ptr_no->dado;
free(ptr_no);
return dado;
}
}
In the code snippet ptr_no->proximo = NULL;
, considering that immediately below I execute the command free(ptr_no);
which will already release the memory allocated to struct ptr_no
and its internal variables, is it redundant and unnecessary to undo the value? >