1 char a = 256; 2 int b = a; 3 b++; 4 cout << b << endl; // 答案是1
#include "stdafx.h" #include <iostream> using namespace std; struct TSA { int a; int b; int c; }; struct TSB { int a; int b; int c; int d; }; int _tmain(int argc, _TCHAR* argv[]) { struct TSA sa[] = {{3},{4},{5},{6}}; struct TSB *psb = (struct TSB *)sa+1; printf("%d %d %d %d\n", psb->a, psb->b, psb->c, psb->d); return 0; }
数组sa初始化以后 内存中的值是3 0 0 , 4 0 0 5 0 0 6 0 0 然后强制转化到TSB类型 结果就是 0050了