mardi 8 janvier 2019

Is there a way for accessing the variable in main from another function?

This problem asks me about a possible number I could replace HUH? with so that it prints hello world and then terminates without any errors.

I tried to figure out the address of x in the main function and used some hexadecimal subtraction between the local variable x in the doit function and the address of x in the main function, but no avail. Is there a way for me to perhaps access the contents of the x in the main function and change that value to 0?

Doing so would cause the while loop to stop running and print out "Hello World".

Is this a feasible approach?

void doit(void) {

int x[1];

x[HUH ? ] = 0;

}

int main(void) {

int x = 1;

while (x > 0)

{

doit();

}

printf("hello world");

}

Aucun commentaire:

Enregistrer un commentaire