2017-01-09 121 views
-3

我试图编译在Ubuntu(64位)下面的代码,以开发-C++ 5.9.2ISO C++禁止在指针和整数之间进行比较[-fpermissive] | [C]

#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行,我的编译器给我的错误

为什么不能做这项工作“[错误]无效从‘诠释’到‘诠释*’[-fpermissive]转换”?我想了解目前的问题。

+1

为什么如果您使用C++标记为'c'? – melpomene

+3

你显示的代码中的哪一行是行号51和57?请用例如一条评论。 –

+1

你似乎混淆了'int'和'int *'。在你的'main'中,'choix'是一个'int','&choix'是一个'int *'。在'menuPrincipale'中,'choix'是一个'int *','choix'是一个'int **'(指向int的指针)。 – Kevin

回答

0

指针

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()您的不当使用指针说。

相关问题