读书人

数据的内存结构有关问题

发布时间: 2012-12-14 10:33:07 作者: rapoo

数据的内存结构问题

C/C++ code
#include "stdafx.h"#include <iostream>using namespace std;typedef unsigned  char u1;typedef   signed  char i1;typedef unsigned short u2;typedef   signed short i2;typedef unsigned  long u4;typedef   signed  long i4;int _tmain(int argc, _TCHAR* argv[]){    u2 n1 = 11;    u2 n2 = 12;    u2 n3 = n1<<8 | n2;    cout<<n1<<endl;    cout<<n2<<endl;    u1 *p = (u1 *)&n3;    cout<<(int)p[0]<<endl;    cout<<(int)p[1];    getchar();    return 0;}


输出是
11
12
12
11

不知道为什么我放进去的数据和得到的数据不一样
是内存结构的问题吗?

读书人网 >C++

热点推荐