vendredi 5 juillet 2019

program state in C

I just started programming in c, and I want to test some code. So, I need to know the value of a variable at a specific point in the program which I already know.

while searching I saw many people are using gdb and core dump but most of the examples I found they use it to debug the code if there is a crash. in my case, I don't want to terminate the execution, I just want to save/know the value of a specific variable at a specific point.

for example:

if I have this piece of code:

int func(int x){

x = 3 * x;

if(x > 0){

    x = x % 4;
    /* I want to know the value of x at this point*/
}
else {

    x = x + 1;
    /* I want to know the value of x at this point*/
}

return x;

}

if the user enters the value, I want to know what will be the value of x inside the block of (if) after the calculation.

Aucun commentaire:

Enregistrer un commentaire