2017-01-09 10 views
-3

私はUbuntuの(64ビット)に以下のコードをコンパイルしようとしています、++ライン51上の5.9.2ISO C++はポインタと整数の比較を禁止しています[-fpermissive] | Dev-Cと[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; 
} 

は、私のコンパイラは私に「ISO C++の比較を禁止エラーが発生しますポインタと整数の間[-fpermissive] "ライン57上

、私のコンパイラは私にエラーを与える "[エラー] 'int型*' から 'int型から無効な変換[-fpermissive]"

はなぜこの仕事をしますか?私は現在の問題を理解したい。

+1

C++を使用している場合、なぜこのタグが 'c'ですか? – melpomene

+3

コードのどの行に51行目と57行目が表示されていますか?それらを例としてマークしてください。コメント。 –

+1

あなたは 'int'と' int * 'を混合しているようです。あなたの 'main'では、' choix'は 'int'で'&choix'は 'int *'です。 'menuPrincipale'において、' choix'は 'int *'であり、 '&choix'は' int ** '(intへのポインタへのポインタ)です。 – Kevin

答えて

0

他の人がmenuPrincipale(に言ったように、あなたが誤って使用してポインタ)ので、あなたのあなたの問題のようにポインタ

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 

の基本。

関連する問題