Function without explicit definition

    I am learning C ++. Dabbling with pointers came up with an interesting example for himself. He probably won’t interest experienced people, but I’ll risk it anyway.
    typedef int (*pf)(int, int);
    char c[] = {85,-119,-27,-117,69,12,3,69,8,93,-61,-112};
    pf sum = (pf)c; //reinterpret_cast здесь не работает.
    cout << sum(2,3); //Вывод 5.

    * This source code was highlighted with Source Code Highlighter.
    Now sum is a function of addition, which is analogous to this:
    int sum(int a, int b){return a+b;}

    The only useful application that I can come up with is to scare the danger of such ghosts.

    UPD . As iley suggested to me , this generally refers to C.

    UPD . In one line:
    cout << ((int (*)(int, int))"\x55\x89\xE5\x8B\x45\x0C\x03\x45\x08\x5D\xC3")(2,3)
    (thanks 0lympian for the thought and halyavin for the amendment)

    Also popular now: