什么是的sizeof(2.5)等于? [英] What is sizeof(2.5) equal to?
问题描述
这是考试的问题是:
Q2:的sizeof(2.5)
等于____
Q2:
sizeof(2.5)
is equal to ____.
A.1
B.2
C.3
D.4
有没有这样的后缀,如佛罗里达州佛罗里达州
,所以浮点常量(2.5)
具有双重型。由于指定的没有别的,我想它的价值是不确定的。例如,在一些实现的 CHAR_BIT
32(导致的sizeof(字符)==的sizeof(长)
,也许),答案可能是B.
There are no such suffixes as f l F L
, so floating-point constant (2.5)
has a double type. Since nothing else is specified, I suppose its value is unspecified. For example, on some implementations whose CHAR_BIT
is 32(causing sizeof (char)==sizeof (long)
, maybe), the answer can be B.
然而,在大多数情况下,其中 CHAR_BIT
是8,答案应该是8位,但8上未纸列出!
However, in most cases, where CHAR_BIT
is 8, the answer should be 8, but 8 isn't listed on the paper!
当在考试/面试问这样一个荒谬的问题,我应该怎么回答?
When asked such a ridiculous question in a exam/interview, what should I answer?
PS:只是忽略这些无用的括号,请:)
PPS:?是IEEE 754标准的批准
PS: Just ignore these useless parentheses please :) PPS: Is IEEE 754 granted by the standard?
推荐答案
此问题是不一致的:的sizeof(2.5)
是实现定义。如果没有额外的背景下,人们不能确定哪个回答选择。
This question is inconsistent: sizeof(2.5)
is implementation defined. Without extra context, one cannot determine which answer to choose.
如果这是一个口腔检查,你能解释一下这个考官和应该得到给你多少已经知道一个很好的标志。 (顺便说一句IEEE-754为不可以的标准,但的一个非常普遍的执行法定双
)。
If this is an oral examination, you can explain this to the examiner and should get a very good mark given how much you already know. (btw IEEE-754 is not mandated by the Standard, but a very common implementation of double
).
如果是书面考试,你可以不给进一步的解释(边际空间其事稀少),你应该选择 4
,原因如下:
If it is a written exam for which you cannot give further explanation (the marginal space being to exiguous), you should select 4
for the following reasons:
-
考官可能错误地假定
2.5
是一个浮动
,也错误地假定浮动
永远是32位,进一步假设错误的字节是8位。这是最可能的解释。在一个口试留如果你认为你知道的比考官好谦虚认真,很可能是这里的情况。
the examiner might erroneously assume
2.5
to be afloat
, and also erroneously assumesfloat
to always be 32 bits, further erroneously assuming bytes to be 8 bits. This is the most probable explanation. Be careful in a oral exam to stay humble if you think you know better than the examiner, it is probably the case here.
这个问题可能是拼写错误,如的sizeof(2.5)
,但缺少对于这个问题,答案肯定是
4
,这将是有意义的尝试和愚弄与 C中的学生
答案。
the question might be misspelt, such as sizeof("2.5")
but missing the "
. For this question, the answer is definitely 4
, and it would make sense to try and fool the student with the C
answer.
这个问题可能是拼写错误,如的sizeof('2.5')
,但缺少
。对于本非常难看的问题,答案是一样的的sizeof(INT)
,常 4
与8位字节系统。
the question might be misspelt, such as sizeof('2.5')
but missing the '
. For this very ugly question, the answer is the same as sizeof(int)
, often 4
on systems with 8 bit bytes.
在某些DSP系统中双击
为64位和字符
16位,答案 4
将是正确的。
on some DSP systems where double
is 64 bits and char
16 bits, answer 4
would be correct.
其他答案甚至不太可能是正确的,当然除了在 DS9K
计算机上。
other answers are even less likely to be correct, except of course on the DS9K
computer.
这篇关于什么是的sizeof(2.5)等于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!