Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1008519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:47:01+00:00 2026-05-16T08:47:01+00:00

So this is a purely academic question, mostly as its been a while since

  • 0

So this is a purely academic question, mostly as its been a while since I’ve done anything too complex in C++. But is there any way to know if a method is taking a paramter as a reference or a value? This isn’t important for pointers, as if you try to pass a non-pointer to a method that takes a pointer, you get a compile error. But something like


int someFunction(int &x){

x = 0

return x;

}

int main(){

int v = 4;

int l = someFunction(v);

I realize that this could be avoided by declaring v as const. But I was just wondering if there was a way to know at runtime if someFunction is taking a reference or a value?

Tagged as C and C++, is there a difference in how either one handles this?

My mistake about C. It's been a long time since I've worked in just C and I've forgotten exactly where the boundary is, lol

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:47:01+00:00Added an answer on May 16, 2026 at 8:47 am

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a purely academic question, but what's the difference between using == and
I have a purely academic question about SQLite databases. I am using SQLite.net to
This might be an odd question, but it has actually caused me some headache.
I was working with bit shift operators (see my question Bit Array Equality )
Is there ever reason to think the >> (signed) and >>> (unsigned) right bit-shift
I realize that, generally speaking, there are performance implications of using reflection. (I myself
I was just messing around to answer someone's question here on Stack Overflow, when
Long version... A co-worker asserted today after seeing my use of while (1) in
Let's face it. The Singleton Pattern is highly controversial topic with hordes programmers on
I am using the Silverlight Unit Testing Framework to test some View Manager classes.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.