为什么两种情况下数组的大小都不相同
Why is the size of array not same in both the cases?
#include<iostream>
using namespace std;
void f(int arr[])
{
int a=sizeof(arr);
cout<<a;
}
int main()
{
int n;
cin>>n;
int arr[n];
int a=sizeof(arr);
cout<<a<<"n";
f(arr);
}
输出:
24
8
为什么即使我打印相同数组的大小,我的输出在这两种情况下也不相同?
在第一次调用中,它显示数组的大小。但在第二种情况下,它显示传递的指针的大小。
当数组通过函数传递时,它们会衰减为指针。所以通过后,:
sizeof(array)
显示指针的大小。
相关文章:
- 两种情况下的输出不应该相同吗?
- 为什么'const'在这两种情况下的行为不同?
- 在哪种情况下,C++会在编译时进行数组边界检查?
- free():仅在一种情况下指针无效
- 在两种情况下,铸造的工作方式不同
- 如果ConstexPR似乎仅在两种情况有效时起作用
- 为什么在一种情况下,我会收到带有字符串文字的已弃用转换警告,而在另一种情况下却没有?
- 我如何仅在一种情况下或某些情况下专业攻击效果
- 在哪种情况下,可以在堆栈上分配
- StrcMP的两种情况
- 程序在没有调试符号的情况下崩溃,运行良好(两种情况下都没有优化或任何内容)
- 在每种情况下都执行“std::set”对元素进行排序
- 为什么在使用C++模板的这两种情况下会出现差异
- c在这两种情况下是如何工作的以及有什么不同
- 为什么两种情况下的行为不同1.int i=1,2,3;和第二.int i;i=1,2,3;
- 为什么两种情况下数组的大小都不相同
- 条件反射为四种情况下的两个数字的符号
- 在哪种情况下,我可以在C++中使用==直接比较两个浮点变量
- 两种情况下wchart字符积分值的差异
- 为什么sizeof(数组)在这两种情况下不同