&a evaluates to a pointer to int rather than int, therefore a reference to int is an incompatible type. Further, returning a reference to a non-static local variable is an extremely bad idea because the local variable is destroyed after the function returns; the reference will refer to a non-existent object.
I know it can be solved if function is defined as "int* example()", but in prototype of that task, function is defined as "int& example()". Is it then impossible to do it like that (which would mean that prototype is wrong), or there is some way?
Real task is something like this: there is a Stack (defined as class), with protected "array" (actually, pointer to dinamically alocated array) called container, which has a function called "int& top()", which returns reference of last element in that array. Something like this:
That makes much more sense, a realistic example is far more helpful than a broken example. You simply need to remove the address-of operator and returning a reference will work in this case because the array has the same lifetime as the stack object: