zoukankan      html  css  js  c++  java
  • 关于sizeof的几个问题

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 int main(int argc, char const *argv[])
     5 {
     6     char *pstr;
     7     int a[]={1,2,3,4,5,6};
     8     pstr=(char *)malloc(sizeof(char)*10);
     9     printf("%d
    ", sizeof(pstr));
    10     printf("%d
    ", sizeof(a));
    11     return 0;  
    12 }  

    运行结果:

     sizeof求的是字节数啊啊啊啊啊啊!!!!!!!!!!!!!!

     另:sizeof是一个关键字而不是函数


    结构体字节对齐问题:

    #include <stdio.h>
    
    struct ts
    {
        char c;
        int n;
    };
    
    int main(int argc, char const *argv[])
    {
        struct ts t;
        printf("sizeof(t.c)=%d
    ", sizeof(t.c));
        printf("sizeof(t.n)=%d
    ", sizeof(t.n));
        printf("sizeof(t)=%d
    ", sizeof(t));
        return 0;
    }

     运行结果:

    注意看sizeof(t)大小为8哦,说明成员c被补成4字节了

  • 相关阅读:
    利用requests, beautifulsoup包爬取股票信息网站
    Mac自带编码转换工具iconv
    Flask 快速入门
    HTML模版组件
    JavaScript正则表达式及jQuery回顾
    jQuery 教程
    Document
    Document
    Document
    Document
  • 原文地址:https://www.cnblogs.com/fallenmoon/p/7598458.html
Copyright © 2011-2022 走看看