gpt4 book ai didi

c - 这些陈述是什么意思?

转载 作者:行者123 更新时间:2023-12-04 11:31:04 26 4
gpt4 key购买 nike

#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));
}
}

我无法理解声明“A”和“B”。如何以及已完成哪些工作?请解释清楚。

最佳答案

语句A是声明

int (*p)[2];      ^      p isint (*p)[2];     ^       p is a pointerint (*p)[2];        ^    p is a pointer to an arrayint (*p)[2];         ^   p is a pointer to an array of 2int (*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 sopint=(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>或可变函数或 ...

关于c - 这些陈述是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5530218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com