代码之家  ›  专栏  ›  技术社区  ›  Jake Wright

C中的复合类型、常量和自动++

  •  3
  • Jake Wright  · 技术社区  · 8 年前

    我正在努力理解这段代码。我一直在想为什么 d e int* const int* . 我需要一些帮助。

    const int ci = i, &cr = ci;
    auto b = ci; // b is an int (top-level const in ci is dropped)
    auto c = cr; // c is an int (cr is an alias for ci whose const is top-level)
    auto d = &i; // d is an int*(& of an int object is int*)
    auto e = &ci; // e is const int*(& of a const object is low-level const)
    
    1 回复  |  直到 8 年前
        1
  •  5
  •   Vittorio Romeo    8 年前

    &i 方法 “获取地址 i " . 自从 是一个 int ,类型 &我 int* . 的类型 d 推断为 内景* 由于 automatic type deduction rules .

    同样的推理也适用于 ci . 唯一的区别是 const 合格者