मुझे ओरियन के जवाब पसंद हैं। मैं दो चीजें जोड़ूंगा:
- बाएं से दाएं अभी भी पहले
लागू होता है
- कार्य को कॉल करने से पहले सभी तर्कों को हल करने के लिए आंतरिक-से-बाहरी
मान लें कि हमारे पास निम्न उदाहरण है:
a = Foo(5, GetSummary("Orion", GetAddress("Orion")),
GetSummary("Chris", GetAddress("Chris")));
निष्पादन का आदेश यहां दिया गया है:
GetAddress("Orion")
GetSummary("Orion", ...)
GetAddress("Chris")
GetSummary("Chris", ...)
Foo(...)
- Assigns to
a
मैं सी # की कानूनी आवश्यकताओं के बारे में बात नहीं कर सकता (हालांकि मैंने इस पोस्ट को लिखने से पहले मोनो का उपयोग करके एक समान उदाहरण का परीक्षण किया था), लेकिन जावा में यह ऑर्डर गारंटी है।
And just for completeness (since this is a language-agnostic thread as well), there are languages like C and C++, where the order is not guaranteed unless there is a sequence point. References: 1, 2. In answering the thread's question, however, &&
and ||
are sequence points in C++ (unless overloaded; also see OJ's excellent answer). So some examples:
foo() && bar()
foo() & bar()
In the &&
case, foo()
is guaranteed to run before bar()
(if the latter is run at all), since &&
is a sequence point. In the &
case, no such guarantee is made (in C and C++), and indeed bar()
can run before foo()
, or vice versa.