异常数组不衰变成一个指针?

问题描述:

我很多帖子已经看到,在大多数情况下数组名称衰变为指针。结果我能知道在何​​种情况下/ EX pressions数组名称不衰变成指针第一要素?

I have seen in many posts that "in most of the cases array names decay into pointers".
Can I know in what cases/expressions the array name doesn't decay into pointers to first elements?

当然可以。

在C99有三种基本的情况,分别是:

In C99 there are three fundamental cases, namely:


  1. 在它的&放大器的参数; (地址)的运营商

在它的的sizeof 运营商的说法。

在它的文本类型的字符串的char [N + 1] 或宽字符串文字类型的 wchar_t的[N + 1 ] N 是字符串的长度),用来初始化数组,如字符海峡[] =富; wchar_t的WSTR [] = L富;

When it's a string literal of type char [N + 1] or a wide string literal of type wchar_t [N + 1] (N is the length of the string) which is used to initialize an array, as in char str[] = "foo"; or wchar_t wstr[] = L"foo";.

此外,C11,新推出的 alignof 运营商不让其数组参数衰变成一个指针无论是。

Furthermore, in C11, the newly introduced alignof operator doesn't let its array argument decay into a pointer either.

在C ++中,有额外的规则,例如,当它通过引用传递

In C++, there are additional rules, for example, when it's passed by reference.