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. |
相关文章推荐
- Question 38: What is the output of the program below in C++?
- linux安装问题:what is the location of the gcc program on your machine
- Programming Basic--what is the output of the following code?
- 安装vmware-tools出现"what is the location of the "ifconfig"program on your machine?"
- what is the location of the gcc program on your machine
- VMware安装Ubuntu17.04的VMware-tools提示:what is the location of the "ifconfig" program on your machin问题解决
- linux安装问题:what is the location of the gcc program on your machine
- 安装vmware-tools出现"what is the location of the "ifconfig"program on your machine?"
- What is the purpose of the USB?
- 76 What is the effect of increasing the value of the ASM_POWER_LIMIT parameter? A. The number of DBW
- vmserver安装出错What is the location of the directory of C header files that match your running kernel?
- what is new - .NET 4.5: review of the ThreadLocal
- The State of Visual Analytics Views on what visual analytics is and where it is going
- 安装 vm tools 时提示“what is the location of the ifconfig”
- What is the difference between SVD and matrix factorization in context of recommendation engine?
- What do you think is the role of parents in preventing crime amongst young people?
- 软件随想录(local.joelonsoftware.com/wiki)-2001年05月05日 这个国家的狗做什么工作? - What Is the Work of Dogs in this Cou
- What is the Big O analysis of this algorithm?(Stackoverflow)
- what is the purpose of the rptproj.user file
- [转] What is the point of redux when using react?