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'
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.
...
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.