0

The c function with param such as :

void test(int fp, int &pos){ //do something... }

But i don't understand what does "int &pos" meant .
Thank you very much for your help

Rndp13
  • 1,094
  • 1
  • 21
  • 35
林开盛
  • 41
  • 6
  • That isn't C, it is probably C++. – juanchopanza Jun 20 '15 at 07:15
  • Doesn't that mean pass the int by reference? – Patrick Roberts Jun 20 '15 at 07:16
  • It means that when you call this function, you pass this parameter **by reference** and not **by value**. In other words, instead of creating **a copy** of the variable (or constant value) that you pass to the function, you pass **the address** of that variable (and you cannot pass a constant value because it doesn't have an address in memory). You can then change this variable inside the function, and affect its value **outside** the function (which is not the case when you pass it by value). BTW, this is valid C++ syntax, not C. – barak manos Jun 20 '15 at 07:23
  • I finally understand ,thanks a lot. – 林开盛 Jun 20 '15 at 07:27

1 Answers1

1

It means that pos is made a reference variable to the variable being passed during function call(their address becomes the same).ie, any change in pos reflects in the calling variable.For example :

If function call

  test(f,p);

changes made to pos will reflect in p.

Sourav Kanta
  • 2,727
  • 1
  • 18
  • 29