Current location - Training Enrollment Network - Mathematics courses - C language function learning
C language function learning
Personally, I think the point of this part of the function is to tell you:

The return value type of 1. function is the content type returned by the function. Note that if there are multiple ways to end a function, there must be multiple returns, such as.

int fun(int x)

{

if(x & gt; 0)

Returns 0;

other

Returns1;

}

2. The transfer relationship of function parameters, some can change the value, some can't change the value, also give an example:

void fun 1(int x,int *y,int & ampz)

{

x = 1;

* y = 1;

z = 1;

}

If the main function has variables inta = b = c = 2; Fun (a & amp; b,c); , then the values of b and c will change, and the value of a will not change, because:

A does not operate on the contents of the memory space occupied by variable a.

& ampB is the memory address of the incoming variable B, and the fun function directly operates the memory space where the variable B is located, so B will change.

As for c, I don't need to know for the time being, because the formal parameter int &;; C stands for reference, which will be involved in c++. You use C now, so just know that there is such a method for the time being.

3. Just pay attention to the lifetime of variables in the function, which is a bit troublesome. Please read the part about local variables and global variables in the book, which is more detailed.