This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

error: declaration may not appear after executable statement in block

Hello,

 

I get the following error-post: declaration may not appear after executable statement in block.

But I do not know whats wrong in my code. The code is this:

 

// In einer for-Schleife wird der Speicher mit 19% der Anzahl der Messwerte mit Zufallszahlen gefüllt
 int anz;
      for ( anz=0;anz == (1000/10)*1.9; anz++)
      {
          int rand(int);    // Funktion rand des Typs integer liefert Rückgabewerte des Typs integer
         rand(anz); // Array der Messwerte wird mit Zufallszahlen gefüllt
      }

 

I guess the declaration of int anz is not right. But I do not know why.

 

Can someone help me...

 

Greetings,

Isabelle

  • In C - you can declare variables only at the beginning of the function (not after any executable code).  The compiler is likely complaining because you have declared the "anz" variable after other code within your function.  Move "anz" to the beginning of your function, and you should be good.