0
点赞
收藏
分享

微信扫一扫

sizeof的使用要点

琛彤麻麻 2022-02-08 阅读 84

要点01

数组名当做指针使用,但其自身并不是指针。

说明

int main(void)
{
    int b[10];
    int *pt = b;
    
    while (1)
    {
        res = sizeof(b);   //40
        res = sizeof(pt);  //4
    }
}

要点02

获取结构体大小。

说明

typedef struct _STDENTS
{
    int name;
    int age;
    int height;
} STUDENTS;

int main(void)
{
    STUDENTS *students = malloc(sizeof(STUDENTS));
    
    res = sizeof(STUDENTS);
    res = sizeof(students);
    
    while (1)
    {
        memset(students,0,sizeof(students));//使用误区
    }
}
举报

相关推荐

0 条评论