sizeof()函数求各类型变量所占空间的方法

#include "stdafx.h"
#include 
using namespace std;

void func(char str[100])
{
    cout<<sizeof(str)<<endl;
}

int  main()
{
    char str[100];
    func(str);    //str传入函数做参数,做sizeof运算时被当做指针 返回4
    cout<<sizeof(str)<//返回整个数组占用的内存空间 100*1
    int str1[100];
    cout<<sizeof(str1)<//返回100*4

    char str2[]="hello";
    cout<<sizeof(str2)<//6
    char *p=str;
    cout<<sizeof(p)<//32位WinNT平台下指针都是4字节
    cout<<sizeof(*p)<//char型字符  返回1

    void *p11=malloc(100);
    cout<<sizeof(p11)<//指针  返回4
    return 0;
}

sizeof()函数求各类型变量所占空间的方法_第1张图片

转载于:https://www.cnblogs.com/audi-car/p/4404465.html

你可能感兴趣的:(sizeof()函数求各类型变量所占空间的方法)