4 ms·
The question is "what would the return value be," and without knowing which compiler is used you don't know what it would return. It doesn't make sense to say
by kmill 10y ago
The question is "what would the return value be," and without knowing which compiler is used you don't know what it would return. It doesn't make sense to say the program returns "undefined behavior" or "implementation-dependent."
You might be taking issue with the question itself, but I think it's a valid question because C compilers tend to be lenient with what they compile.
- gkya 10y agoI can't know != I don't know
- amelius 10y agoYes, and "I can't know" is a stronger assertion than "I don't know". The former implies the latter. However, both are correct.
- gkya 10y agoThing is I can know if the necessary information is provided (i.e. CPU architecture, version of the standard). Portability is a feature of C, but C's portability is mostly syntactic and only partly semantic.
- jwdunne 10y agoBut if the necessary info isn't provided, you don't know because, as you say, you can't know. It's semantics. On many exams, "don't know" is a correct answer when you can't know because info is intentionally left out.
- gkya 10y agoI don't really want to be a pedant here, but in this case if the necessary information was provided, I had the knowledge to find a correct answer. This is different from the case where even if the information was provided I wouldn't be able to know because I don't have the necessary knowledge.