一元 + 可接收指针,实现类型的转换:
#include <cstdio>
int main()
{
int a[3] = {1,2,3};
const auto& x = +a;
const auto& y = a;
}
Insight:
#include <cstdio>
int main()
{
int a[3] = {1, 2, 3};
int *const & x = +a;
int const (&y)[3] = a;
}
加减法可以接收指针:
#include <iostream>
int main()
{
int a[3] = {1,2,3};
std::cout << std::cend(a) - std::cbegin(a) << std::endl;
} //输出3,即为数组a的长度
一元 + 会发生integral promotion:
(减法也会,但一般会改变正负)
#include <iostream>
int main()
{
short a = 6;
auto b = + a;
}
Insight:
#include <iostream>
int main()
{
short a = 6;
int b = +static_cast<int>(a);
}
整数相除会产生整数,向 0 取整
求余只能接收整数类型操作数,结果符号与第一个操作数相同
满足 (m / n) * n + m % n == m