简单的c++问题 在线等
//经常在结构体里看到 char data[1];这样的结构 我做了个测试 产生了疑问
struct ST{ int a; char aa[1];};int _tmain(int argc, _TCHAR* argv[]){ ST* pst = NULL; char* pszBuff = new char[100]; pszBuff[0] = 0; pszBuff[1] = 0; pszBuff[2] = 0; pszBuff[3] = 0; //int的 4个byte pszBuff[4] = 'z'; pszBuff[5] = 'y'; pszBuff[6] = 'b'; pszBuff[7] = '\0'; pst = (ST*)pszBuff; ST st; memcpy(&st,pst,sizeof(ST)); cout << int(pst->aa) << endl; cout << int((st.aa)) << endl; //2个地址不同 cout << *(pst->aa+1) << endl; //但是+1都能定位到'y' cout << *(st.aa+1) << endl; cout << int((pst->aa)+1) << endl; //但是+1的地址又不同。。 cout << int((st.aa)+1) << endl; //既然+1的地址不同 那为什么他们的值都是'y' return 0;}