主题:字符指针赋值给整型指针问题
如下代码:
void main(void)
{
char a[10] = {0,1,2,3,4,5,6,7,8,9};
int *ptr;
ptr = (int*)a;
printf("*ptr = %d\r\n",*ptr);
printf("*(ptr+1) = %d\r\n",*(ptr+1));
}
本以为输出为0和4,但是却输入乱七八糟的值,请问各位大侠这是什么原因,谢谢
void main(void)
{
char a[10] = {0,1,2,3,4,5,6,7,8,9};
int *ptr;
ptr = (int*)a;
printf("*ptr = %d\r\n",*ptr);
printf("*(ptr+1) = %d\r\n",*(ptr+1));
}
本以为输出为0和4,但是却输入乱七八糟的值,请问各位大侠这是什么原因,谢谢