auto * p =&n`和`auto p =&n`之间的区别吗?

问题描述 投票:1回答:2
#include <type_traits>

int main()
{
    int n;

    auto* p1 = &n;
    auto  p2 = &n;

    static_assert(std::is_same_v<decltype(p1), decltype(p2)>); // ok
}

auto* p = &nauto p = &n之间有区别吗?还是只是编码样式问题?

c++ c++11 syntax coding-style auto
2个回答
1
投票

auto* p = &nauto p = &n之间有区别吗?


-2
投票

除了可读性之外没有其他区别。这是因为您要获取右侧的l值的地址。地址只能存储在指针中,因此编译器将能够确定auto应该是什么。

© www.soinside.com 2019 - 2024. All rights reserved.