Partage
  • Partager sur Facebook
  • Partager sur Twitter

Error in goto statement in my C program

    10 janvier 2023 à 10:28:02

    I am trying to use the goto statement in my C code, but I am receiving an error when I try to compile it. Could anyone help me understand why this might be happening and how I can fix it? Here's an example of the code that is causing the issue:

    #include <stdio.h>
    
    int main() {
        int a = 5, b = 10;
    
    here:
        printf("a = %d, b = %d\n", a, b);
        if (a > b) goto here;
        return 0;
    }

    The error I'm having:

    error: jump to label 'here' crosses initialization of 'int b'
    





    • Partager sur Facebook
    • Partager sur Twitter
      10 janvier 2023 à 11:10:47

      Quel compilateur utilises-tu ? Je n'arrive pas à reproduire l'erreur.

      Mise à part un while serait plus approprié. Le goto on l'évite autant que possible.

      • Partager sur Facebook
      • Partager sur Twitter
      ...

      Error in goto statement in my C program

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown