首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

内存储器中的各变量分配验证

2012-12-25 
内存中的各变量分配验证#include iostreamusing namespace stdstruct S{int achar bint cchar dcha

内存中的各变量分配验证

#include <iostream>using namespace std;struct S{int a;char b;int c;char d;char e;int f;double g;int h;};int main(){S s;s.a = 10;s.b = 'b';s.c = 30;s.d = 'd';s.e = 'e';s.f = 60;s.g = 70.0;s.h = 80;cout<<sizeof(s)<<endl;void* x = &s;cout<<*(int*)x<<endl;//ax = (int*)x+1;cout<<*(char*)x<<endl;  //bx = (int*)x+1;cout<<*(int*)x<<endl;//cx = (int*)x+1;cout<<*(char*)x<<endl;//dx = (char*)x+1;cout<<*(char*)x<<endl;//ex = (char*)x+3;cout<<*(int*)x<<endl;//fx = (int*)x+1;cout<<*(double*)x<<endl;//gx = (double*)x+1;cout<<*(int*)x<<endl;//hreturn 0;}


输出结果为:
32
10
b
30
d
e
60
70
80

热点排行