+2  A: 

Yes. In any language it is possible to create a function that returns different results based on whether the function uses pass-by-value or pass-by-reference. This shouldn't be used in day-to-day programming, but it is useful for testing the compiler, testing an API, etc. Basically, call your function with a variable that is initialized to some value, and in the function, assign a different value to the parameter. In the caller, check the value of the parameter after you've invoked the function to see if the mutation has had a visible effect. Note that I am assuming that you've written both the caller and the callee.

If you want to check some arbitrary function that you don't have control over, you can use function overloading to tell you what type of parameter passing scheme is in use:

bool IsPassingByReference(int (*func)(int)) { return false; }
bool IsPassingByReference(int (*func)(int&)) { return true; }

As has been noted, this is applicable to C++ only. (C has pointers, but no references).

Michael Aaron Safyan
A: 

AFAIK there is no way to know this at runtime. Or at compiletime for that matter. C++ is just not build this way. You should look up "Reflection" - the ability of a program to know about its own structure. C++ hasn't got it, Java for example has.

C does not have references.

Gabriel Schreiber
A: 

This question looks a bit strange. You want to know at runtime something that is already known at compile time. So, direct answer for someFunction is: yes, its parameter is reference, because it is reference. And this is known both at compile and runtime. Such kind of questions are usually asked by template writers, who need to detect parameter type at compile time.

Usually C++ programmers try to do as much as possible at compile time, and you want to do at runtime something that can be done at compile time.

Alex Farber
Yeah I understand it's a weird question. But I just got to thinking after reading another question here. Let's say that you know nothing about the prototype of someFunction. You're only told it takes an int. I know this isn't a very good real world example since you can always just look at the prototype. But this is purely an academic question
Falmarri
+1  A: 

If you're passing some non-basic type (e.g. int, char etc), but rather an instance of some class, you can modify that class's copy-constructor to print something when it's being copied.

Now, if the function uses a value, the copy constructor will be called when you call that function, and if it uses a reference, there will be no copy, and the copy constructor will not be called.

You can check for the presence of that printout to determine if the function used a value or a reference.

Nathan Fellman
That's a really good idea. +1 for that
Falmarri