📜 ⬆️ ⬇️

Function without explicit definition

Learning C ++. Dabbling with pointers came up with an interesting example. He probably won't be interested in experienced people, but I still risk it.
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 an addition function, which is analogous to this:
int sum(int a, int b){return a+b;}

The only useful application that I can think of is to frighten the danger of such ghosts.

UPD . As Iley suggested to me , this refers in general to C.

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

')

Source: https://habr.com/ru/post/71234/


All Articles