Why does it say unused?

I´m on task “generateDict”.
It says, selected1 and selected2 are not used.
Bildschirmfoto 2022-06-03 um 16.36.28
But I’m using them. In my program they just appear on the left side of the sign “=” and never on the right side. (just selected1 = … , never .… = selected1)
Maybe this is the problem?

You are right, the warning tells you that you assign a value, but never use that value (within the scope of the function). You may simply ignore that warning.


While this is possible, the warning is actually really important here, because currently your function is wrong. Assigning but not using variables usually indicates a programming mistake.

Specifically, you are supposed to copy the selected word into the memory referenced by the selected1 pointer. What you actually do is change the selected1 pointer to point somewhere else.

This will not work, since the calling function (ie our tests and the remainder of the game) expect the data to be written to precisely the place in memory that pointer initially points to. If you reassign the pointer itself to point somewhere else, that is only visible in that function, and the calling function does neither know nor expect this.

If this surprises you, it should not. It’s the same principle for why the following program outputs 0, even though we assign x to 42:

void foo(int x){

int main(){
  int k=0;
  printf("%d\n", k);

Note that if variables only appear on the left side (without being behind a *, i.e. they are the entire lvalue), you are not actually using them. You just change their value, but since this is a local variable, the only one who could use the value stored there is you, but you don’t, so it’s not actually used “usefully”.