- 论坛徽章:
- 0
|
#include <string>;
#include <iostream>;
#include <stdlib.h>;
using namespace std;
#pragma pack (1)
struct xxx
{
char a[5];
int b;
}test;
#pragma pack ()
int main()
{
int arg1,arg2;
int end;
char *ma = "abcd";
strncpy(test.a,ma,strlen(ma));
cout<<strlen(test.a)<<endl;
test.b = 300;
void *p = 0;
cout<<"enter first arg ";
cin>;>;arg1;
cout<<"enter second arg ";
cin>;>;arg2;
p = &
char *ch = static_cast<char *>;(p);
cout<<ch<<endl;
cout<<&p<<endl; //这里的地址,和下边的地址一样,未发生变化 ch += arg1;
p = ch;
cout<<&p<<endl; //here
int *res2 = static_cast<int *>;(p);
cout<<*res2<<endl;
cin>;>;end;
}
请教,这个void p的地址为什么不发生改变?换了是char ch,也是未发生变化。 |
|