Warning set of variables, but not used

int none[5]; int ntwo[5]; (the following is in a switch statement); if (answer == userAnswer) { printf("Correct!\n"); score = prevScore + 1; prevScore = score; } else { printf("Incorrect. The correct answer was %d\n\n", answer); none[i] = number1; ntwo[i] = number2; } } break; 

(Ends operator output)

This leads to the error: “The warning about the variable“ none is set, but is not used. ”I used it explicitly. I don’t know why this error occurs. FYI all other variables that you see were declared. I just took imp part where the array appears.

+6
source share
2 answers

none appears twice in this code snippet:

 int none[5]; // declared, not set to anything 

And then:

 none[i] = number1; // a value has been set, but it not being used for anything 

If, for example, you later had:

 int foo = none[3]; // <-- the value in none[3] is being used to set foo 

or

 for(int i = 0; i < 5; i++) printf("%d\n", none[i]); // <-- the values in none are being used by printf 

or something like that, we would say that none "used", but since there is code, you have: "none" set but not used ; exactly what the compiler said.


In the pastebin link, I see your problem:

You wrote this:

 for(i=0;i<5;i++) { printf("Question [i]: none[i]+ntwo[i]"); 

You wanted to write this:

 for(i=0;i<5;i++) { printf("Question [i]: ", none[i]+ntwo[i]); 

None is now used, and your print does something useful ...

+12
source

Using a variable is different than initializing it.

Here you set the value of the variable none, but your compiler will tell you that it is not used, because you never check it with comparison operators or you never pass it to a function.

+3
source

Source: https://habr.com/ru/post/970192/


All Articles