Chapter III Let C Execute Operation
The example of the previous chapter is actually very stupid, that is, use C and uses a line of lines and outputs a sentence. What is the use of this program? Oh, only let you see this, you can't be used as the first example. This chapter is to give a procedure that at least a point of operation, although there is no input only, although it is just a very simple multiplication. However, it is sufficient. The program is to make two numbers multiply and then output the results. The way the output is in the same chapter, in a black-paste window. #include main () {int L, r, res; l = 404; r = 505; res = L * r; Printf ("The result is% d", res);} Run the result is The Result IS 204020 is displayed on the screen. Let's take a look at how the C is calculated and output. The framework of the program is almost similar. They are all in #include , this line allows you to use Printf. Moreover, the program body is in main () {...}. No sentence ends with a selection. Yes, it is almost. Just a few lines of una seen code. 3.1 Variable variables are not a concept in a computer, and have an independent variable in mathematics, due to variables. And the concept of variables in the computer (programming) is derived, but it is not exactly the same. For example, variables have variable types. INT L, R, RES; declare three variables. What is the declaration of variables? We can understand this sentence gives you three names L, R, RES's containers to you, and the type of value has been limited, that is, the int type is also an integer (Integer). (Note 1) 3.2 Assignment to the variable L = 404; what I should be able to understand it. It is to put 404 this integer into this container named L. The process is called assignment. Then r = 505; it is also similar. So rs = l * r;? Type L by R and assign the result to the res. * Is the number (notes 2). So run here, the value of RES is obvious. 3.3 Value of output an integer type variable printf has been used last time. But the usage is different. At least last time only gives a parameter (notes 3). In fact, it is also clear here. RES as the second parameter, intention is the result of output multiplication. % D is the key,% D indicates that this should be an integer type variable, and then the value of the RES will be replaced here.
Note 1: Take the variable is very common. For example, "Computer News" has reported that the variable is called a container in the easy language reported. See www.eyuyan.com in detail. The int type is actually not exact integers because it can only represent a range of integers. This range is different on different machines. Common 32-bit machines are 32 times of 2. Note 2: This symbol has many times in C, but also the meaning of the meaning. Here is just a method of representing multiplication. Alternatively and / and / and / and / constitute a marker. Indicates the pointer type, indicating that the cancel reference is canceled. Note 3: What is the parameter. Take the printf as a function, then there is a single variable function, multi-variable function. () Is the parameter.