gpt4 book ai didi

c - 指向c中指针的指针,

转载 作者:行者123 更新时间:2023-11-30 19:25:15 25 4
gpt4 key购买 nike

感谢您阅读本文。我有个问题。下面的代码就可以了:

int main() {
int x,y;
int* q;
int** w;
x=10;
y=15;
q=&x;
printf("%d\n",*q);
*w=&y;
printf("%d\n",**w);
if(**w<*q){
printf("asdasdasd%d\n",**w);
}else{printf("asdasdas%d\n",*q);}
}

但是这个功能很糟糕:

void funcio(int* tiempo,int* dni,char* patente,int terminar,int bandera){
int** tiempom;
int** dnim;
char** patentem;
if(terminar==0){
if(bandera==0){
*tiempom=&tiempo; //
*dnim=&dni; //
*patentem=&patente; //
bandera=1;
}
if(bandera==1){
if(**tiempom>*tiempo){
*tiempom=&tiempo; //
*dnim=&dni //
*patentem=&patente; //
}
}
}

if (terminar==1){
printf("El dni del chofer con menor tiempo es: %d\n",**dnim);
printf("Su patente es: %c\n",**patentem);
printf("Su tiempo fue de: %i\n",**tiempom);
system("pause");
}
}

warning: assignment to 'int *' from incompatible pointer type 'int **' [-Wincompatible-pointer-types]| warning: assignment to 'char *' from incompatible pointer type 'char **' [-Wincompatible-pointer-types]|

感谢您的阅读<3

最佳答案

您收到该警告是因为您尝试将双指针 (**) 转换为单指针 (*)

void funcio(int* tiempo,int* dni,char* patente,int terminar,int bandera){
int** tiempom;
int** dnim;
char** patentem;

if(terminar==0){
if(bandera==0){
tiempom = &tiempo; //
dnim = &dni; //
patentem = &patente; //
bandera = 1;
}
if(bandera==1){
if(**tiempom > *tiempo){
tiempom = &tiempo; //
dnim = &dni; //
patentem = &patente; //
}
}
}

if (terminar==1){
printf("El dni del chofer con menor tiempo es: %d\n",**dnim);
printf("Su patente es: %c\n",**patentem);
printf("Su tiempo fue de: %i\n",**tiempom);
system("pause");
}
}

关于c - 指向c中指针的指针,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59163294/

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