可以将一个数组强制转换成结构体么?
typdef struct A{char b;long int c;) R;char content[5];
(R) content[5];
可以不可以
2015-03-13 14:23
2015-03-13 15:36
2015-03-13 15:53
2015-03-13 16:01
程序代码:
#include <stdio.h>
int main(void)
{
typedef struct A
{
char b;
long int c;
} R;
R content;
content.b = 'A';
char *read = (char *)&content;
printf("%c\n", read[0]);
return 0;
}
2015-03-13 16:47
2015-03-13 16:48

2015-03-13 16:50
2015-03-13 18:03
2015-03-13 19:49
程序代码:
#include <stdio.h>
#include <stdlib.h>
typedef struct{
int x;
}eg;
char database[32];
int main()
{
eg *para = (eg*)database;
printf("%d\n",sizeof(int));
printf("%d\n",sizeof(char));
printf("%x\n",¶[0]);
printf("%x\n",¶[1]);
printf("%x\n",¶[2]);
printf("%x\n",¶[3]);
printf("%x\n",&database[0]);
printf("%x\n",&database[4]);
printf("%x\n",&database[8]);
printf("%x\n",&database[12]);
}
2020-07-22 16:25