C语言中计算变量占用内存空间

C语言中计算变量占用内存空间

在C语言中通常用【sizeof】运算符计算变量占内存空间,如下面的例子:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQ8AAAEICAIAAADOSObRAAAGJElEQVR4nO3dQW7bVgKAYR0jR+lFspueYIA5RLOe3CFbAzlDjdmkm3Rn5DCzmC4CGB6+x8dfituk4vfBCByZpKj4/aJkPsaXp6enN+++/A84cvlaywU4pBao3r9//+bdl//+9NO3fHzvBwF/iV8//a4WSNQC1aaWy+Xy+PgY11UL56IWqNQClVqgUgtUaoFKLVCpBapNLY8vHK6rFs5lPLZ0auFc1AKVWqBSC1RqgUotUKkFqr3zLWVdtXAue8cWZydhSy1QqQUqtUD19X/f24x77/JhYqzFjH2Y29TSU7mohbOZvhKL1MK57NXiXT5sff782bWTkGxquWpdtXAuaoFKLVCpBSq1QKUWqNQC1bQWsyphYqzFlcYwpxaoxpkvF6/EYMr7FqjUApVaoFrM2D9sRi2ci2MLVGqByisxqMwTg0otUKkFqrdv36oFkof/fFQLJGqBSi1QTWtxdhImxlpcDQZzaoFqU4trJ2GX9y1wBbVA4tgC1fi+xYx9mHNsgeofH9QCmVdikDx8+Nk8MUjMqoRKLXAFtUDi2AKVWqBSC1TO5UM1/g9JrgaDOb93Eiq/dxIqv5ECKrVApRao/LYjqBxboFILVF6JQfbLv80Tg0YtUKkFqn+6dhIixxao1AKVWqD6/1rimZav1MLJ7LzLL8GohXP518fJzJeLWmA0nSd2UQuMzKqEajqrMq6rFs7FsQUq71ugUgtUaoFq79rJsq5aOJe9Y0uhFs7l4eFBLZD89tsntUCiFqjUApVaoHoe8d/y8b0fBPwl1AKVWqAah7s5LzCnFqjUApVaoFILVGqBSi1QqQWql4O+/9JJtXBGtw16tXBGaoFKLVCpBSq1QKUWqNQC1d75lrKWWjiX50G/KcTZSdhSC1RqgWpv0KsFtqaD3rt8mDBjH6rNoPd7jmDX5nzLVWuphXPxMzGoXtbi2klYMU8MKrVApRao1AKVWq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UKkFKrVApRao1AKVWqBSC0R/AHQTDlrEXnTXAAAAAElFTkSuQmCC" alt="" />
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
short a;
int b;
long c ;
double e;
float d;
//赋值
ch = 'a';
a = ;
b = ;
c= ;
d = 1.5;
e = 1.5; printf("%d\n",sizeof(char));
printf("%d\n",sizeof(short));
printf("%d\n",sizeof(int));
printf("%d\n",sizeof(long));
printf("%d\n",sizeof(float));
printf("%d\n",sizeof(double)); printf("%d\n",sizeof(ch));
printf("%d\n",sizeof(a));
printf("%d\n",sizeof(b));
printf("%d\n",sizeof(c));
printf("%d\n",sizeof(d));
printf("%d\n",sizeof(e));
system("pause");
return ;
}
上一篇:【POJ3621】【洛谷2868】Sightseeing Cows(分数规划)


下一篇:洛谷4951 地震 bzoj1816扑克牌 洛谷3199最小圈 / 01分数规划