Why does this simple code not work?

I have a variable Rst as an integer. This I assigned the value "2". When I press a key, the variable is assigned the value "5".

const int RstPin = 39;
void setup() {
 pinMode(RstPin, INPUT_PULLUP);
 Rst = 2;
void loop() {
  if (digitalRead(RstPin == LOW)) { // Wenn Reset gedrückt
       Rst = 5;

A "5" is output from the beginning, whether I press the button or not.
How can I change the value of a variable at runtime?

Change your digitalread to like below:

if (digitalRead(RstPin) == LOW)

Perfect. Thanks for the quick and competent help.

I assume you understood why this change is made. But the others may seek why,

When we want to digitalRead something it should be in () brackets. We may define a variable to point a pin, or it could be directly pin's number. In this case OP wants to read state of pin 39 which is declared as RstPin.

When you try to digitalRead it only accepts pin's numbers which is always a number of pin.

"digitalRead(RstPin == LOW)"

as you can see we trying to read "RstPin == LOW" pin which makes no sense. We must point a pin number

So digitalRead(RstPin) is what we want, we declared RstPin as 39 so compiler knows RstPin means 39.

By design digitalRead returns HIGH or LOW

then we check if statement is true or false

if (digitalRead(RstPin) == LOW)

Just elaborate on what omersiar said.

"digitalRead(RstPin == LOW)" will in fact always read pin0 (whatever that maps to). The reason is that LOW is (currently) defined as 0 and Rst is equal 2 at the time of comparison. So obviously "RstPin==LOW" evaluates to FALSE, which is numerically zero in C.

Hence the program will always attempt to read pin0 in that program.