以下程序输出各种c语言数据类型在内存中所占字节
#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>
int main()
{
/*c语言内置类型*/
printf("the size of char is: %d\n", sizeof(char)); //1
printf("the size of short is: %d\n", sizeof(short)); //2
printf("the size of short int is: %d\n",sizeof(short int));//2
printf("the size of int is: %d\n", sizeof(int)); //vc:4 tc:2
printf("the size of long int: is %d\n",sizeof(long int)); //4
// printf("the size of long long int is: %lld\n",sizeof(long long int)); //4
// cout<<sizeof(long long)<<endl; //vc不支持long long
printf("the size of float is: %d\n", sizeof(float)); //4
printf("the size of double is: %d\n", sizeof(double)); //8
/*字符串以及字符串数组*/
char a[]={'a','b','c','d','e'};
printf("size of a[] is:%d\n", sizeof(a));//5
char b[] = "zbcd";
printf("size od b[] is %d:\n", sizeof(b));//5
char c[][3] = {{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'}};
printf("size of c[][] is %d:\n", sizeof(c));//12
printf("size of c[0] is %d:\n", sizeof(c[0]));//3
printf("size of c[0][0] is %d:\n", sizeof(c[0][0]));//1
/*指针所占字节数*/
char *p = NULL;
printf("size of char *p is %d:\n", sizeof(p));//4
printf("size of char * is %d:\n", sizeof(char *));//4
printf("size of int * is %d:\n", sizeof(int *));//4
printf("size of float * is %d:\n", sizeof(float *));//4
printf("size of double * is %d:\n", sizeof(double *));//4
/*字符数组所占字节*/
char d[][5] = {"abcc","deff","ghii","jkll"};
printf("size of d[0] is %d:\n", sizeof(d[0])); //输出某一行所占字节
printf("size od d[0][0] is %d:\n", sizeof(d[0][0]));//输出某一元素所占字节
system("pause");
return 0;
}