Thursday, September 18, 2008

C...learning: Chapter 4 of 8 "Functions"

I've used simple functions handling -without variables passing- hundreds of time in C++ and so I just viewed the introductive parts.

I still can't fully get the usance of "Categories of Saving Variables" (extern,static,auto,register ) and specifically the extern but I think I will lately with "files direction"

Now the issues about pointers in functions. The first notable of the chapter
float z = 3
float* const pointer= &z
you can change the contect (*const pointer=5;) and not the adress (const pointer = &a;)

const float * pointer=&z;

you can change the adress but not the content.
However you can change the variable of the adress.
So this is the way for changing the content in this case

If you want to completely lock both pointer and the variable then you have to do this


About references its the way to pass the adresses from variables of a function to another functions. But from the time the function has the adresses, nothing stops her to change their content. So its the way for changing the variables passed to other functions.

Now, about the form of this process we have the example

main()
{ int x=5, y=10;
function (&x, &y); ...}

void function (int* x, int*y)
{ *x=0;
*y=0; }

You declare pointers in the function and so you pass them the adresses. Now you have the power to change them

When you're passing an array, you just pass its adress so you can either pass the array's name, or a pointer - for an arrays name its actually an adress of the array

You have also the ability to pass pointers.

Therefore you can even make a function call itself - flashback (anadromh in Greek)!

No comments: