Either you print the integer with %d
printf("The result is: %d\n", num);
or the string representation with %s
printf("The result is: %s\n" , str);
By doing
printf("The result is: %d" , sprintf);
You are printing the decimal representation of the address of the function sprintf. Example:
#include <stdio.h>
int main() {
int num = 158;
char str[5];
sprintf(str, "%d" ,num);
printf("The result is: %d\n", sprintf);
printf("The result is: %8x\n", sprintf);
}
Compile statically in order to make it easier to locate the address of sprintf.
➜ ~ [4] [Thu 13] $ gcc file.c -o bin -static
In the code, I also print the hexadecimal representation, which is easier to locate in the binary file. Output:
The result is: 4200768
The result is: 401940
You can actually check the linear address of sprintf in the ELF executable:
➜ ~ [4] [Thu 13] $ nm bin | grep sprintf
0000000000480830 W asprintf
0000000000480830 T __asprintf
0000000000480830 T ___asprintf
0000000000401940 T _IO_sprintf
0000000000480a40 T _IO_vasprintf
00000000004019d0 T __IO_vsprintf
00000000004019d0 T _IO_vsprintf
0000000000401940 T sprintf
0000000000401940 T __sprintf
0000000000480a40 W vasprintf
00000000004019d0 W vsprintf
As expected, 0x0000000000401940.