Click here to Skip to main content
15,671,383 members
Please Sign up or sign in to vote.
3.00/5 (4 votes)
See more:
What function argument i have to pass to function Myfunk,c without changing the defition?

void MyFunc(int * & data) {data++;}
void main () {
 int a = 5;
 cout << a;

What I have tried:

I have tried the address memory of the &a.
Updated 2-Feb-17 7:01am

You have to pass a reference to an int*:
int someVal = 123;
int *pSomeVal = &someVal;
Because a reference must be an lvalue, you must create a variable rather than just passing the address of a variable which is not an lvalue.

Because your function is incrementing the pointer, using an array makes more sense (avoid out-of-bounds access):
int someVals[] = { 1, 2, 3 };
int *pSomeVal = someVals;
cout << *pSomeVal;
Share this answer
It takes a reference to a pointer (to int).
Try, for instance:
#include <iostream>
using namespace std;

void MyFunc(int * & data) {data++;}

int main ()

  int a [] = { 12, 15, 27, 42 };

  int * p = &a[2];

  cout << *p << endl;

  MyFunc( p );

  cout << *p << endl;
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900