How to fix "warning: statement has no effect" in C++? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

How to fix "warning: statement has no effect" in C++?

Hello everyone, I'm writing code to find the middle of a link list but it returns me nothing when complied. Here is my code: int numOfNodes(struct listNode * firstNode){ int countNodes = 0; while(firstNode -> next != NULL){ countNodes ++; } return countNodes + 1; } int middleOfList(struct listNode * firstNode){ int count = 0; int numb = numOfNodes(firstNode); int previous; while(count != numb / 2) { if (count == (numb / 2) - 1){ previous = firstNode -> num; count++; ** firstNode -> next; } else{ count++; ** firstNode -> next; } } if(numb % 2 != 0) { return firstNode -> next -> num; } else { int total = ((firstNode -> next -> num) + previous) / 2 ; return total; } } The first function just counts the number of nodes there are in the link list. the second function however (middleOfList) gives me the warning where you see the ** in the function.(firstNode -> next). The complier is telling me that it has no effect but that is how I iterate through the link list to find the middle of it. This is probably the reason why it returns me 0 every time, meaning that it has no errors. Could someone please tell me where I am going wrong? All answers will be appreciated and thanks in advance.

5th Jan 2020, 1:15 AM
Leo Hunter
Leo Hunter - avatar
0 Respuestas