相关疑难解决方法(0)

当函数具有特定大小的数组参数时,为什么它被指针替换?

鉴于以下计划,

#include <iostream>

using namespace std;

void foo( char a[100] )
{
    cout << "foo() " << sizeof( a ) << endl;
}

int main()
{
    char bar[100] = { 0 };
    cout << "main() " << sizeof( bar ) << endl;
    foo( bar );
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出

main() 100
foo() 4
Run Code Online (Sandbox Code Playgroud)
  1. 为什么数组作为指向第一个元素的指针传递?
  2. 它是C的遗产吗?
  3. 标准说什么?
  4. 为什么C++的严格类型安全性下降了?

c++ arrays standards sizeof function-parameter

65
推荐指数
2
解决办法
3万
查看次数

标签 统计

arrays ×1

c++ ×1

function-parameter ×1

sizeof ×1

standards ×1