C Language Learning 9th day: function (ii)

Source: Internet
Author: User

Local VariablesLocal variables are also internal variables, used inside the function, can not be used outside the function of the code after the function call ends, local variables accounted for the memory of the auto-free local variables should be defined at the beginning of the program block Global VariablesIf you do not initialize auto clear 0, local variables will produce random values if not initialized; it is visible to the whole program. He does not belong to a function, but to the entire source file generally before the main () function declares global variables such as uninitialized, the system is automatically initialized to 0 Static Local Variablesis initialized only once, is created when the function is first entered, retains its value when exiting the function, and static local variables, like global variables, are initialized to 0 by default; Functions and Arrays1. The array element is passed as an argument 2, and the array name is passed as an argument because the array is the first address of the array. The transfer of an array of function parameters is actually the transfer of the address, that is, the contents of the modified parameter group will change the contents of the real parameter group accordingly. Outreach: sizeof (ARR)/sizeof (arr[0]); sorting by functions; #include <stdio.h>
#define SIZE 10
void Sort (int *p,int len) {
int temp;
for (int i = 0; i < len; i++) {
for (int j = len-1; J >= i; j--) {
if (* (P + j) > * (P + j+ 1)) {
temp = * (P + j);
* (P + j) = * (P + j + 1);
* (P + j + 1) = temp;
}
}
}
}
void print (int *p,int len) {
for (int i = 0; i < len; i++) {
printf ("%d,", * (P + i));
}
}
int main (int argc, const char * argv[]) {
int Arr[size] = {1,3,2,6,5,4,0,9,8,7};
Print (arr,size);
printf ("\ n");
Sort (arr,size);
printf ("Result after sorting: \ n");
Print (arr, SIZE);
return 0;} RecursiveIn the process of invoking a function, there is a direct or indirect call to the function itself, that is, the function of recursive call can be resolved to the problem to the new problem, the solution of the new problem is the same as the original, but the scale of the regular decline of each sub-problem must be smaller than the original problem size. Recursive implementation: 5! #include <stdio.h>
int recursion (int n) {
if (n = = 1) {
return 1;
}
else{
return n * recursion (n-1);
}
}
int main (int argc, const char * argv[]) {
int a = 0;
printf ("Please enter a value within 10: \ n");
scanf ("%d", &a);
int result;
result = recursion (a);
printf ("%d! =%d\n ", a,result);
return 0;}

C Language Learning Day 9th: function (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.