c/c++:sizeof pointer and array

File : sizeof_ptrar.cpp
Type : c/c++
Brief : difference between size of pointer and arrray


#include <iostream>
using namespace std;

int main()
{
    int *ptr = new int[10];
    int ar[10] ={0};

    // 指针变量占空间,32位机占4个字节,64位机占8个字节
    cout << sizeof(ptr) << endl;

    // 整个数组点的空间,10个int占40个字节
    cout << sizeof(ar) <<  endl;

    // 获取数组元素的个数
    cout << sizeof(a) / sizeof(a[0]) << endl;

    return 0;
}

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 [ [email protected] ]