-5

if I have a C program that begins with

#include
int main (void){
.
.
.
}

where approximately is this function? (in hex)

wbur
  • 17
  • 8
  • 1
    What? Call something that reads the return address from the stack, or pops it and jumps to it. Why do you need to know? – Martin James Mar 03 '16 at 11:42
  • Or run it with disassembly view, with a breakpoint at main() – Michał Szydłowski Mar 03 '16 at 11:43
  • got this question on an exam. – wbur Mar 03 '16 at 11:44
  • This depends on platform you are working on,for example in resource constrained embedded systems you can specify the address of the main function,be more specific about the platform. – Vagish Mar 03 '16 at 11:44
  • 1
    @CoolGuy Function pointers are a different class of pointers than normal variable pointers, so `%p` is not correct. See http://stackoverflow.com/questions/2741683/how-to-format-a-function-pointer – Klas Lindbäck Mar 03 '16 at 12:27
  • @KlasLindbäck Thanks! I did not know that. I deleted my incorrect comment. Reading that post you linked… – Spikatrix Mar 03 '16 at 13:00

1 Answers1

1

Like this:

#include <stdio.h>

int main() {
    unsigned char *p = (unsigned char *) &main;

    int i;
    for (i = 0; i < sizeof &main; i++)
    {
        printf("%02x ", p[i]);
    }
    putchar('\n');

    return 0;
}

Output on my machine:

55 48 89 e5 48 83 ec 20 

Reference: https://stackoverflow.com/a/2741896/5399734

Community
  • 1
  • 1
nalzok
  • 14,965
  • 21
  • 72
  • 139