O
O
OwerFan2018-11-25 11:46:53
C++ / C#
OwerFan, 2018-11-25 11:46:53

How does an address pass into a pointer in a function?

#include <iostream>
 using namespace std;
 void func(int *func_number) {
  *func_number = 5;
}
 int main() {
  setlocale(0, "");
  int main_number = 10;
  func(&main_number);
  cout << main_number;
   system("pause");
  return 0;
}

When a function is called, the void func(int *func_number)compiler automatically puts the address main_numberinto the *func_number?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Melnikov, 2018-11-25
@OwerFan

Strange question
&main_number taking the address from the main_number variable
When the function is called, this address is passed to the func
function Inside the function, this parameter is called func_number
And what is the question? What is the difference?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question