C++ Passing Pointer to Function (Howto) + C++ Pointer Manipulation -


I understand how the passing pointers work.

Assume that I have the following function and the pointer, and ...

Edit :

... function As an argument, I want to use an object as an object.

i.e.:

  zero fun (int pointer) {int Fun_Ptr = --- Passed Pointer ---; / / So that Fun_Ptr indicates that whatever - passed pointers indicates  

* between pointers and pointers notation, I am very confused I know that Pointer means that whatever he points out.

Will I put zero (int * pointer) in the declaration?

Edit 2:

OK, now I understand that using the variable * in the declaration means that an indicator will be passed though When I use the function, then what about?

i.e.

  int main () {int foo; Int * bar; Bar = foo; Fun (bar); }  

Edit 3: OK, then correct me if I am wrong:

According to the conventions of the above code: < / P> bar = & amp; Foo means: Create a bar point to foo in memory

* bar = foo means that equals bar to equal, which is equal to foo equal

< P> If I have the second indicator (insert * off) then:

Bar = OOF means: bar number for off pointers

bar = 'OOF means : The bar points for the value that indicates the OOF digit, but not the OOF pointer

* bar = * oof means: change that value That Oof points which indicates that according to the value

& amp; Bar = & amp;; Off means: To change the memory address, which bars the number as a memory address

Do I have this right? Edit 4: Thank you very much for all your help (I wish I can accept more than 1 answer, but I have to go first with one. I am not sure that a community wiki How actually works, but I will leave it for editing in this way, rotate it if you wish, in the referee guide).

A variable and when you are using it.

In the announcement,

  int * myVariable;  

An indicator is an integer data type. However in use,

  * myVariable = 3;  

Respect the indicator and the structure indicates it is equal to three, but rather make the marker equal to the address of 0x 0003.

Then, the function, you want to do this:

  zero MakePointAqual something (integer * pInteger) {* pInteger = 7; }  

In the Function Declaration, * means that you are passing an indicator, but * in its actual code body means that you are reaching the point that indicator indicates Has been doing.

In an effort to overcome any confusion, I will briefly go to Ampersand (& amp; nbsp;)

& amp; Means the address of some, its correct location in computer memory, therefore

  int & amp; MyVariable;  

An announcement is an integer or an indicator's address!

Although this

  int someData; PInteger = & amp; Some data;  

means the pInteger pointer itself builds (remember, points are only memory addresses for things that are equivalent to the address of 'some data') - so now the pinter will point to some data, And it can be used if it is used:

  * pInteger + = 9000;  

Do you understand this? Is there something else that confuses you?

@ edit3:

Almost right except for three statements;

  bar = * oof;  

means that the bar indicator is equal to an integer, not the bar number, which is invalid

& amp; Bar = & amp; Oof;

Ampersand is like a function, once it returns a memory address, then you can not modify it from where it came from. Just like this code:

returnThisInt ("72") = 86;

is invalid, then you have it.

Finally

  bar = oof  

does not mean that "bar pointers to bar pointers" means The address at which OOF points, indicates the same point, which indicates Fu - does not have a bar number for Fu which points to the OFF


Comments