void problem3(void) {
int overflowme[16];
int x = (int) problem3; // x is the address of the first instr for problem3
printf("hello world\n");
overflowme[17] = x;
I'm wondering what does the (int) do in C programming.
It's a typecast, and tells the compiler "Ignore the type that problem3 really has, and deal with it as if it were typed as an int".
In this example, problem3 has a function pointer type, so normally the compiler would reject the program (Using a function pointer when an integer is expected is normally a programmer error). The typecast forces a different interpretation - the programmer is stepping in and saying "I know what I'm doing".
It's an explicit cast. You are casting the value of problem3 to an integer and then assigning that integer value to x.
Note that this does not actually change the value of problem3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With