I also want to learn C language-Chapter 8: Process Control and Function Mechanism

Source: Internet
Author: User

I. Process Control

Today, I learned how to control the process! I practiced three program processes for three hours. During the learning process, I saw a sentence "sequence, branch, and loop can describe any algorithm ." It seems that it is a problematic algorithm to describe the problem using, sequence, branch, and loop. Note! Process control requires a large number of exercises on various algorithms. So it's only hard work to learn this well!

Ii. Functions

  1: function declaration: Function return value function name (format parameter type ........)

{

Function Code Block

If necessary, return (expression) is also required)

}

  2: Functions: Encapsulate the details! Because you need a function, you only need to read the declaration of this function. Because the name of a good function has a lot of meaning, you will know what it is, and implement Modular programming. And the function can be used repeatedly, just like a bowl of food! As long as the food is good, you can use the same bowl for each meal. And! Each "bowl" is also independent. It is washed one by one after washing, and some "Dirty (bug)" are washed!

  3: form parameters and real parameters: The parameter accepted when the function is defined is called a form parameter, and the value given to the function when the function is called is a real parameter.

  3: function Running Mechanism:

Value transfer:

#include <stdio.h>

void change(int a, int b)
{
int temp = a;
a = b;
b = temp;
}

int main(void)
{
int i = 0;
int j = 1;

change(i, j);

printf("i=%d", i);
printf("j=%d", j);

return (0);
}

Hey! What do I think! In this way, the values of two variables are exchanged! But the results are depressing! Not exchanged! Why! Debug 1 and check the progress!

Now we are about to enter the switching function!

Oh! This is the case! Look! The addresses of the parameters a, B, and ij are different! Only replicas are exchanged! Clone! Take a closer look, the real parameters and the form parameters are just the same value, and the address is different! If only the form parameter and the real parameter are exchanged, there is no relation at all! Just like a lot of bad children, she wants to curse people, and she wants to buy a doll and treat it as a nasty person! Then, we constantly curse the doll every day, thinking that this will make others unlucky. Alas! In fact, her curse has no effect at all! I used to think it was really useful. Now I have learned functions, and I think it is really useless! O -- o! This is why scanf used to take the address!

Since functions interact like this, we can summarize the call process of function 1!

  1: parameter Replication(Write down "the main characteristics of the enemy" in this document ")

  2: Save the return address(When I buy a "doll", I am worried that it is not so bad, or I will give it to the merchant one day! So write down the seller's detailed address !)

  3: Open up memory space(When I buy a "doll", it will occupy a certain amount of space in the universe)

  4. Plan local variables(Then dress up for the doll to make it look more like that person, and prepare a "prop" to curse it! Draw a circle or something, haha !)

  5: Execute the function body code(Then we start to "curse !)

  6: Undo memory space(Well! Curse tired! Alas! I think this is really not a good child. I still want to send the doll back to the merchant !)

  7. Get the return address(One day I realized that this was incorrect, so I was ready to return the doll to the merchant! So take out the detailed address of the seller that was previously written down in this book !)

  8: The parameter's memory space is revoked.(Alas! Since we want to be a good child again, let's continue with the previous "book !)

3: the person who is still "current" (the parameter's memory space is revoked-set in c/c ++'s Calling convention in Project Settings in vc6.0 (also called the call convention ))

There are several ways to continue the "Ben" issue!

1: Let the seller "continue" this book! In this way, the "Merchant" (the function caller) will know that it was a bad child before and should be new to itself now! In this way, the "Merchant" can witness my change! The seller also knows where the child used to be bad and buys a few dolls (number of parameters). This means that the next time the child wants to buy a doll, she may be even worse, I want to buy a lot of dolls, so the merchants get the dolls into the old ones. You can use multiple parameters (printf and scanf )! -- _ Cdecl

2; 3: How about _ fastcall and _ stdcall! If it is still "Ben", I will continue to do it myself. In this way, it is better not to tell others about shame. Hey!

Related Article

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.