gpt4 book ai didi

c - ISO C++ 禁止指针和整数之间的比较 [-fpermissive]| [C]

转载 作者:行者123 更新时间:2023-11-30 21:07:52 26 4
gpt4 key购买 nike

我尝试在 Ubuntu(64 位)上使用 Dev-C++ 5.9.2 编译以下代码

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

// Afficher les nombres parfaits inférieurs ou égaux à un entier donné
void parfaitInf(int n)
{
int i, j, somme;
for(i=2;i<=n;i++)
{
somme=1;
for(j=2;j<=i/2;j++)
{
if(i%j==0) somme+=j;
}
if(somme==i) printf("%d\n",i);
}
}

// Tester si un entier est un nombre d'Armstong
void armstrong(int n)
{
int somme=0,m=n;
do
{
somme+=pow(m%10,3);
m/=10;
}
while(m!=0);
if(somme==n) printf("%d est Armstrong.\n",n);
else printf("%d n\'est pas Armstrong !\n",n);
}

// Calculer la racine carrée d'un nombre entier
void racineCarree(int n)
{
printf("La racine carr%ce de %d est %f",130,n,sqrt(n));
}

void menuPrincipale(int *choix)
{
do
{
printf("\t\tMenu\n");
printf("[1] Afficher les nombres parfaits inf%rieurs ou %cgaux %c un entier donn%ce\n",130,130,133,130);
printf("[2] Tester si un entier est un nombre d\'Armstrong\n");
printf("[3] Calculer la racine carr%ce d\'un nombre entier\n\n",130);
printf("Votre choix ? ");
scanf("%d",&choix);
}
while(&choix<1 || &choix>3);
}

int main()
{
int n,choix;
menuPrincipale(choix); //compilation error here
printf("%d",&choix);
// Not Continued
return 0;
}

在第 51 行,我的编译器给出错误“ISO C++ 禁止指针和整数之间的比较 [-fpermissive]”。

在第 57 行,我的编译器给出错误“[Error] invalid conversion from 'int' to 'int*' [-fpermissive]”

为什么这不起作用?我想了解当前的问题。

最佳答案

指针基础

int i = 1;
int *p = &i; // p is a memory address of where i is stored. & is address of variable.

int j = *p; // j is the value pointed to by p. * resolves the reference and returns the value to which the pointer addresses.

int **dp = &p; // dp is the address of the pointer that itself is an address to a value. dp->p->i

cout << i; // 1
cout << p; // 0x.... some random memory address
cout << j; // 1
cout << dp; // 0x... some random memory address that is where the p variable is stored

因此,正如您的问题一样,正如其他人在 menuPrincipale() 中所说的那样,您错误地使用了指针。

关于c - ISO C++ 禁止指针和整数之间的比较 [-fpermissive]| [C],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41551665/

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