-function Format: Declare output variable type function name (parameter) {function code} example:int sum (int a,int b) {int c=a+b; re Turn C;} Use the function name directly such as: int num=sum (10,20), where sum is a summation function, the above code represents the sum of 10 and 20 and a variable of type int, NUM receives the result of the function,it can be num=30 after printing, and we can construct the function according to the above function, we define the functions we need, such as finding the product function and so on, even many complex functions (function libraries) .A function can extract a function that is relatively independent so that it can be reused multiple times in other programs as a function's encapsulation
-Formal parameters and argumentsThe above function, A, b are the formal parameters of the int type, 10, 20 is the actual parameter, the formal parameter argument is only the value of the pass, the 10 is passed to a, 20 is passed to B, so the function of a+b in order to get the actual data results C is the formal parameter
-Array format: element type array name [array length]; Example:int a[10]; the subscript starts at 0, until the length-1; the character array needs to be an end symbol, so it takes one more length. Using subscript to access the elements in the array, the array must never be out of bounds, so when you write the array, you need to add security to avoid the array out of bounds, once created, you cannot change the size array is an ordered data container in memory is a contiguous memory (pointer offset), Only one type of element can be stored in an array note: A string is a traversal of an array stored with a character array, typically using the for loop to iterate over element one by one in the group:for (int i=0, i < Array.Length, i++)Length = sizeof (array)/sizeof (array[0]); This way, when the element type of an array changes without changing its array length, the code array itself cannot be assigned a value to assign an array to another array can only take the method of traversal, the array as a function parameter often must be used to represent the size of the array with another parameter and passed in, not in the incoming array of [] to the size of the group String is a character array char[4] A string representing four characters
-pointer take address character & gets the address of the variable in memory space, pointer is the variable that holds the address int *p = &i; This code means taking the address of the variable i and assigning the variable p, if i = 24; You can get *p = = 24; The value of the normal variable is the actual value: i = = 24, whereas the value of the pointer variable is the address of the variable with the actual amount, although there is *p = = i = = 24; But P is a 16-bit decimal number, which means that the address of the memory space The problem of the physical parameter and the actual parameter in the function directly to the operation of its data is a lot of inconvenience, such as to write a function and pass in two parameters the function implements the exchange of the value of the two parameters passed in this function Since both parameters are directly exchanged in the function, their values have no effect on the two parameters in the main function outside the function that require the value to be exchanged, that is, the function did not achieve the effect we expected. At this point, if you use the pointer in the function directly in the memory space for the variables that need to exchange values, the result is returned by the pointer, can solve the above problem. Symbol * is a single-mesh operator used to question the value of the pointer represented by the variable on the address-pointer to array relationship: The array in the function parameter table is actually the pointer array variable is a special pointer The array variable itself represents the address so the address of the array does not need to use the address character & eg:int a[10]; int*p = A; But an array element represents a variable fetch address when you need to use the Fetch address & eg:int*p = &a[0]; In fact, because an array is a pointer, there is such a relationship to an array: a = = &a[0]; p[0] = = A[0]; The array described above in memory is a contiguous memory pointer is a variable pointing to memory so there is a pointer offset problem, the pointer offset will cause the pointer to the memory offset and the array is a contiguous memory So just get the offset of the pointer we can still get the offset after the pointer points to which element in the array. Brief introduction: int array[4] = (11,22,33,44); int *p = array; There are: *p = = Array[0]; p[0] = = array[0] = = 11; pointer offset: p[3] = array[3] = = 44; int *q = &array[2]; &NBSP;Q[-1] = array[1] = = 22;
C language-functions, arrays, pointers