zoukankan      html  css  js  c++  java
  • Question #49: What is the output of the program?

    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.

  • 相关阅读:
    优化-IO
    优化-cpu
    优化-内存
    系统优化
    snort -- 入侵检测系统
    tripwire--入侵检测系统
    sudo
    selinux
    pptpd
    C++ 内联函数
  • 原文地址:https://www.cnblogs.com/rickiedu/p/1455054.html
Copyright © 2011-2022 走看看