#include<stdio.h>
void main() {
int s[4][2]={
{1,2},
{3,4},
{5,6},
{7,8}
};
int (*p)[2]; // what does this statement mean? (A)
int i,j,*pint;
for(i=0;i<=3;i++) {
p=&s[i];
pint=(int*)p; // what does this statement mean? (B)
printf("\n");
for(j=0;j<=1;j++) {
printf("%d",*(pint+j));
}
}
Run Code Online (Sandbox Code Playgroud)
我无法理解陈述'A'和'B'.如何做和做了什么?请非常清楚地解释一下.
声明A是声明
int (*p)[2];
^ p is
int (*p)[2];
^ p is a pointer
int (*p)[2];
^ p is a pointer to an array
int (*p)[2];
^ p is a pointer to an array of 2
int (*p)[2];
^^^ p is a pointer to an array of 2 int
语句B是带有嵌入式强制转换的赋值表达式
pint=(int*)p;
^ take the value in p (of type "pointer to array of 2 ints")
pint=(int*)p;
^^^^^^ take the value in p, convert it to 'pointer to int'
even if it doesn't make sense to do so
pint=(int*)p;
^^^^^ take the value in p, convert it to 'pointer to int'
and put the resulting value (whatever that may be) in pint
演员阵容很糟糕.尽可能避免演员表演.
(*)除非在非常特殊的情况下,例如<ctype.h>或变量函数或......