3
while (variavel != (struct lista*)0) {
...
}
How to interpret (struct lista*)0)
? What does that mean?
3
while (variavel != (struct lista*)0) {
...
}
How to interpret (struct lista*)0)
? What does that mean?
4
(struct lista*)
is a cast, then the code is telling the compiler to interpret the value below as being of this specified type, i.e., a pointer to a structure called lista
previously declared. In this case it is only a way to make it clear that you know you are doing it and that is exactly what you want, ie the variable variavel
must be exactly the type struct lista *
, since 0
originally is a type int
, with the 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 indicator, then the loop will stop when the value of variavel
is void.
Browser other questions tagged c struct cast
You are not signed in. Login or sign up in order to post.
How would the cast look without the pointer? Example: struct variable list. Thanks for the clarifications.
– WillBill
Simple as that just takes the pointer out, but it doesn’t mean it will work in all cases.
– Maniero