利用指针强制转换
#include <iostream>using namespace std;
#define SIZE sizeof(char) + sizeof(short) + sizeof(int) + sizeof(double)
void main()
{
char a1, a2;
short b1, b2;
int c1, c2;
double d1, d2;
char array;
a1='a';
b1=1;
c1=230;
d1=0.9;
array = a1;
*(short*)(array + 1) = b1;
*(int*)(array + 3) = c1;
*(double*)(array + 7) = d1;
a2 = array;
b2 = *(short*)(array + 1);
c2 = *(int*)(array + 3);
d2 = *(double*)(array + 7);
std::cout << a2 << " " << b2 << " " << c2 << " " << d2 << std::endl;
system("pause");
}
<
*(short*)(array + 1) = b1;
*(int*)(array + 3) = c1;
*(double*)(array + 7) = d1;
a2 = array;
b2 = *(short*)(array + 1);
c2 = *(int*)(array + 3);
d2 = *(double*)(array + 7);
>这一段指针的运用实在看不懂。请大神们指点指点小弟。。{:5_111:}
页:
[1]