由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ Q35: sizeof() (B20_20)
相关主题
C++面试题目分享(2)刷题是程序员和工程师的分水岭
Best C++ book一道码公电面题(nvidia),怎么做
好心人帮忙推荐一本C++入门书算法题目一问
Answers to Exercises from "The C++ Programming Language"bloomberg相关的面试题
马工就别靠内推找工作了这题到底什么意思?
电面被羞辱了,求安慰~~~刚刚结束的linkedIn电面
再问一个C的malloc( )一道onsite面试题
C++ Q78: about sizeof请教 Iterator 一题
相关话题的讨论汇总
话题: sizeof话题: int话题: size话题: enumerator
进入JobHunting版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
What is the size of an enumeration type?
a) sizeof(size_t)
b) 2
c) 4
d) sizeof(int)
e) implementation-defined
x***y
发帖数: 633
2
actually, enumerator can be cast to int; but inside a class, enumerator is
like static, no memory won't be allocated for a particular object...
c**********e
发帖数: 2007
3
So the answer is e)?

【在 x***y 的大作中提到】
: actually, enumerator can be cast to int; but inside a class, enumerator is
: like static, no memory won't be allocated for a particular object...

x***y
发帖数: 633
4
Not sure...It may be stored in data segment, but it must have a size at
least sizeof(int) to be able to be converted to int...

【在 c**********e 的大作中提到】
: So the answer is e)?
c**********e
发帖数: 2007
5
The absolute size of integral types is generally implementation defined, and
as this question further shows, the size of an enumeration is not even
required to be the size of a specific integral type.
d) sizeof(int)
This is incorrect. This is the common wrong answer. Enumeration types may
allow values that will not fit in the range of an int.
e) implementation-defined
This is correct. The actual size of an enumeration type depends in part on
the magnitude and sign of the enumerator values. Ho
x***y
发帖数: 633
6
good to know....

and
on
to

【在 c**********e 的大作中提到】
: The absolute size of integral types is generally implementation defined, and
: as this question further shows, the size of an enumeration is not even
: required to be the size of a specific integral type.
: d) sizeof(int)
: This is incorrect. This is the common wrong answer. Enumeration types may
: allow values that will not fit in the range of an int.
: e) implementation-defined
: This is correct. The actual size of an enumeration type depends in part on
: the magnitude and sign of the enumerator values. Ho

P********l
发帖数: 452
7
Cool bean, dude.

and
may
on
rules to

【在 c**********e 的大作中提到】
: The absolute size of integral types is generally implementation defined, and
: as this question further shows, the size of an enumeration is not even
: required to be the size of a specific integral type.
: d) sizeof(int)
: This is incorrect. This is the common wrong answer. Enumeration types may
: allow values that will not fit in the range of an int.
: e) implementation-defined
: This is correct. The actual size of an enumeration type depends in part on
: the magnitude and sign of the enumerator values. Ho

l****5
发帖数: 95
8
According to Bjarne Stroustrup's book "The C++ Programming language
(special edition)" page 78 (the very top):
"The sizeof an enumeration is the sizeof some integral type that can
hold its range and not larger than sizeof(int), unless an enumerator
cannot be represented as an int or as an unsigned int".
Here integral type include Boolean, character and integer types.
Please also refer the discussion here
http://stackoverflow.com/questions/1113855/is-the-sizeofenum-sizeofint-
always

defined, and

【在 c**********e 的大作中提到】
: The absolute size of integral types is generally implementation defined, and
: as this question further shows, the size of an enumeration is not even
: required to be the size of a specific integral type.
: d) sizeof(int)
: This is incorrect. This is the common wrong answer. Enumeration types may
: allow values that will not fit in the range of an int.
: e) implementation-defined
: This is correct. The actual size of an enumeration type depends in part on
: the magnitude and sign of the enumerator values. Ho

1 (共1页)
进入JobHunting版参与讨论
相关主题
请教 Iterator 一题马工就别靠内推找工作了
求教一个, Leetcode 题.电面被羞辱了,求安慰~~~
问一道g的题再问一个C的malloc( )
面试的时候可以用STL吗C++ Q78: about sizeof
C++面试题目分享(2)刷题是程序员和工程师的分水岭
Best C++ book一道码公电面题(nvidia),怎么做
好心人帮忙推荐一本C++入门书算法题目一问
Answers to Exercises from "The C++ Programming Language"bloomberg相关的面试题
相关话题的讨论汇总
话题: sizeof话题: int话题: size话题: enumerator