您的位置:首页 > 产品设计 > UI/UE

Question #49: What is the output of the program?

2009-05-12 16:48 417 查看
Question #49: What is the output of the program?

55% on 10074 times asked

#include <iostream>
class Foo
{
public:
char c;
static double sd;
double d;
int i;
};
int main(int argc, char** argv)
{
Foo f = { 72, 3.14 };
std::cout << f.c + f.d + f.i << std::endl;
return 0;
}


72
75.14 - correct
ill-formed
undefined
description: "An aggregate is an array or a class with no user-declared constructors, no private or protected non-static data members, no base classes, and no virtual functions." Aggregates can be initialized by "brace-enclosed, comma separated list of initializer-clauses for the members of the aggregate, written in increasing subscript or member order." Static data members are skipped during this type of initialization so 3.14 initializes d and not sd in this example "If there are fewer initializers in the list than there are members in the aggregate, then each member not explicitly initialized shall be value-initialized". So in this example i is value-initialized to 0.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐