#How does this return syntax work?

14 messages · Page 1 of 1 (latest)

hazy parcel
#

So I am looking through a code and see this syntax in the return of functions. I dont know how to google for it, so I am asking here.

Syntax in question:

return fIterator ? fIterator->Next() : nullptr;
weary tulipBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

shell scarab
#

If fIterator is true it returns the object before :

#

If false it returns nullptr

sleek copper
#

So this has little to do with the return statement, and instead what I think you are refering to is the ternary operator

#

<condition> ? <expressionA> : <expressionB>

#

This evaluates to expressionA if the condition is true, or expressionB if the condition is false

shell scarab
#

Just what i said 😅

#

also in this case fIterator is a pointer. So checking ”fIterator” basically returns true if the pointer isnt 0 (aka nullptr).

hazy parcel
#

Ah ok, thank you both. It makes sense now

hazy parcel
shell scarab
#

I can read the future 😏

weary tulipBOT
#

@hazy parcel Has your question been resolved? If so, run !solved :)

hazy parcel
#

!solved