Computer programs must be tracked with 3 basic properties when storing data:
1. Where is information stored?
2. What is the value stored?
3. What type is stored;
Let's take a look at what is the built-in data type of the programming language! (Oh, this is not good to say, because every language has its own unique data type, but this is a few, such as there is a Byte type data in Java, and there is no in C , I hope you can give one more!) Integer "int", floating point type of data "float"! String "string", and arrays also have structures, and so on. However, when writing the program, we will create a type of variable or constant as needed, for example, because we need to create a shaped variable i is 5, we can do this, int i = 5; and I am very It may change the value of i, which is to assign a value from the new to it, such as letting it wait and 6, you can change it in the required place to change to i = 6; thereby, we know that the amount of change can occur on "value" variable. The amount that does not change will be called constant, with the const keyword in C , and in Java, use the final keyword to declare. Due to different languages in different languages, don't be introduced here, detailed content clearing through books!
Here we mainly discuss the function, we can imagine the function as a "black box that implements a specific function" ----- This feature is set by you, for example, for example, now I ask How much "2 3 is equal to?" I believe that you can answer me soon is equal to 5. Let's analyze what information is included in this sentence! First of all, I want to imagine your brain into a black box. I don't know if it is not necessary to know how your brain is working (how is it to operate), what information I did to give you? What processing do you have to do? What information is you returning to me? Need to remind you that every method will return a message to the caller, except for the constructor (later I will make a detailed introduction). I need to take myself as a programmer now, and you? Of course it is a computer! The computer can be so smart, it will only be run according to a specific format in advance, I want it to have the functions as described above, I will define this black box! First of all, I want to tell this black box will have two integer values to you (this is the so-called parameters, the programmer needs to give the black box), then define the two integers to implement the two integers inside the black box (this is The machining made by the black box on the data can do any processing as needed.). Finally, I will be marked it back to give me a value of integer (this is the information of the black box to the programmer). A function is so defined, let's take a look at the writing format:
INT AddNum (int X, int y) {
Return X Y;
}
The specific meaning is like this:
INT / * Return Value Type * / AddNum / * Method (Black Box) Name * / (INT X, INT Y / * Parameter * /) {
RETURN X Y; / * The internal is the method (implement additional operation,) and returns to the caller with RETURN * /
}
First, please pay attention to the "return" statement! The meaning of the return key is to return to the caller to follow the information behind it! Just like above, because I ask you, you will answer me, if I don't ask you, you don't have to answer me! Like the computer, where is the function to call? I can only tell you, where is it to call! Of course, you can change the parameters, return values, and internal implementation as needed, and how to define how to call you had to refer to the relevant information! Here I am just give you a thought! Sometimes you will encounter such problems, I let you remember, my age is 20 years old! Understand from the literal, have you returned to me! However, in fact, you really return information, the content of the information is "no information, that is, there is no return value type void". The specific procedures are as follows:
INT myage = 0;
INT A = 20;
Void Remage (int a) {
MYAGE = a;
}
The specific function is described below:
INT myage = 0; // Defines and initializes my age of 0;
INT A = 20; / * Define variable a equal to 20 * /
VOID / * Return value type is a non-return value type * / remote / * function name * / (int A / * incoming parameters * /) {
Myage = a; // Internal implementation method, pay attention, no return returns! ! !
}
There are still a lot of topics about functions. It will be introduced here. My purpose is to let you know how the function will be! Paper for the following discussion!
1.3 pointer and reference:
The pointer and reference are in C , and there is no in Java. The operation of the memory is canceled in Java, and the operation of the operator overload is also canceled. However, I will still introduce some operator overload functions. The reference is mainly used on the transfer of function parameters. So I don't have too much introduction here. They are very practical, interested in classmates can refer to C related books.
1.4 Operator and control statement:
Still look at the relevant books, this is no longer awkward here!