码迷,mamicode.com
首页 > 其他好文 > 详细

C基础题-sizeof

时间:2017-03-03 22:27:12      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:指针   sizeof   size   span   hello   eof   ret   turn   基础题   

1.
#include "stdio.h"
int main() {
    char str[] = "hello";
    char *s = "hello";
    int a[] = {3, 5, 7};
    printf("%d\n%d\n%d\n", sizeof(str), sizeof(s), sizeof(a));
    return 0;
}
//输出6, 4, 12
sizeof(str)=6   str是数组,sizeof得到的是它的内存空间大小,hello串有一个结束符,共6位
sizeof(p)=4      p是指针,所有的指针都占32bit/8=4字节
sizeof(a)=12      整形int占4字节,


2.
main() {
    char str[]="S\065AB";
    printf("\n%d", sizeof(str));
}
//输出5
\0是八进制0 ,即S,\065,A,B,NULL

 

3.

int a[3];     //12
int b[3][4];      //48
int *c[4];     //16
int(*d)[4];    //4
int **e;       //4
int **f[3];       //12
int **g[3][4];  //48

C基础题-sizeof

标签:指针   sizeof   size   span   hello   eof   ret   turn   基础题   

原文地址:http://www.cnblogs.com/sunziying/p/6498560.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!