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

  • SEARCH
  • Home
  • 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 3488450
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:16:20+00:00 2026-05-18T11:16:20+00:00

I just want to check here on how to pass a reference to a

  • 0

I just want to check here on how to pass a reference to a function that wants a pointer. I have a code example below. In my case, I am passing a C++ reference to a C function that will change my value.

Should I use the ‘&’ address of operator in this call: retCode=MyCFunc( &myVar)? It seems that I am taking a reference of a reference, which is not allowed in C++. However, it compiles fine and seems to work.

MainFunc()
{

    int retCode = 0;
    unsigned long myVar = 0;

    retCode = MyCPlusPlusFunc(myVar);

    // use myVars new value for some checks
    ...
    ...
}

int MyCPlusPlusFunc( unsigned long& myVar)
{
  int retCode = 0;
  retCode=MyCFunc( &myVar);
  return retCode;  
}

int MyCFunc ( unsigned long* myVar) 
{
  *myVar = 5;
}

I thought my code was above was fine, until I saw this example on the IBM site (they do not pass using the ‘&’ address of operator):
http://publib.boulder.ibm.com/infocenter/zos/v1r11/index.jsp?topic=/com.ibm.zos.r11.ceea400/ceea417020.htm

// C++ Usage
extern "C" {
  int cfunc(int *);
}

main()
{
  int result, y=5;
  int& x=y;

  result=cfunc(x); /* by reference */
  if (y==6)
  printf("It worked!\n");


// C Subroutine
cfunc( int *newval )
{
  // receive into pointer
  ++(*newval);
  return *newval;
}

In general, I know you can do the following:

int x = 0;
int &r = x;
int *p2 = &r; //assign pointer to a reference

What is the correct? Should I use the & address of operator in my call or not?

  • 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-18T11:16:21+00:00Added an answer on May 18, 2026 at 11:16 am

    Your usage is correct, to do &myVar to get the address of it and pass to a function that wants a pointer. Taking the address-of a ‘reference’ is the same as taking the address of the referent.

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

Sidebar

Related Questions

Before Entering data into a database, I just want to check that the database
I just want to check if I understood well the way asynchronous Http request
I just want to check if there is any easy way to limit zooming.
I just want to check whether the facebook user is atleast on facebook for
I just want to check and see if a row exists where the $lectureName
Basically I just want to check if one time period overlaps with another. Null
Possible Duplicate: check whether internet connection is available with C# I just want to
I want to check if a checkbox just got unchecked, when a user clicks
I want to create one so that I could check whether a certain word
Here's the situation: I have a predetermined GPS route that the user will run.

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.