How to interpret this line? (struct list *) 0)

3
while (variavel != (struct lista*)0) {
   ...
}

How to interpret (struct lista*)0) ? What does that mean?

    
asked by anonymous 18.09.2018 / 22:15

1 answer

4

(struct lista*) is a cast , so the code tells the compiler to interpret the following value as being of this specified type, that is, a pointer to a structure named lista previously declared . In this case it's just a way to make it clear that you know you're doing it and that's what you want, that is, the variable variavel must be exactly of type struct lista * , since 0 is originally a type int , with cast is guaranteed to be compatible from the point of view of type. But of course, nothing guarantees that the data is what is expected there. The 0 in this case is a null pointer indicative, so the loop will stop when the value of variavel is null.

    
18.09.2018 / 22:20