-
In fact, this is a simple question of variable type and variable function, I think it should be explained like this: first, the original purpose of variable definition is to use the variable we define to meet the needs of our program, so, above you define variable a, then later, you will use this variable to do some operations, in most cases, it is to be initialized, so, give a corresponding type of value to initialize the variable, so that some operations can be used in the future, second, the understanding of that sentence:" You want a to represent 5, so you want to assign the value of a to 5", in fact, it is an initialization process of the variable a, where a is int (integer), corresponding to an initial value of 5, which is expressed like this:
int a=5;The definition is also initialized, so that the variable a represents an integer of 5, and then the value of a can be modified to give it another integer value; (This is also where variables are different from constants, the role of constants is to initialize a corresponding type value at the same time as the definition, and the value cannot be modified in the scope of the program; The variable can be re-assigned, modify or overwrite the original value, and then assign the value of the corresponding type; Third, understanding the meaning of assignment can make you understand that by drawing inferences, other types are like: such as: double b=; Define a variable b of type double, which we want b to represent; So, assign the value of b to so, and b will represent, so you should understand it by now!^
-
To put it simply, the memory space allocated at int a is something that other programs may have used, and the data that has been written has not been cleared. In this way, the data in this memory space may be a value that you don't want. A means 5, which actually means that when you want you to use the value a, the size of a is 5, such as a+1, which is equivalent to 5+1.
In order not to quote a value that is not within your desired range, you need to make the value of a 5, which is called "assigning the value of a to 5".
-
That is, if you want a to be 5, or if you want it to be 10, then int a=10;In fact, these just remember how to assign values, and I also learn C++, if it's useful, for example, I want to find and includevoid main() how to output if you don't give a value.
-
Like you said, at the beginning, when there is no assignment, the value of a can be any value, then if you printf a, the displayed value may be any value, all you need to assign a value, the value you assign to a will automatically replace the original uncertain value stored in a, this is the assignment!
-
The initialization of a variable is to directly assign a value to the variable when defining the variable.
There are generally two ways to initialize the application:
1. Directly initialize the variable by assigning a constant value;
2. Initialize through the same type of variable.
Here are some examples:
The following is the first type of initialization.
int a1=5;inter variable initialization int b1=; Initialization of integer arrays.
char str1="abcd";Initialization of Character Arrays The following is the second type of initialization.
int a2 = a1;int b2[4] = b1 for integer variables; Initialization of integer arrays char str2[4] = str1; Initialization char *p = str1 for character arrays; Initialization of character pointers.
-
Initialization of Global Variables There is no guarantee of the order in which global variables in different compilation units are initialized, so it is unwise to establish dependencies between the initialization order of global variables in different compilation units. In addition, there is no way to catch the exceptions thrown by the initialization of global variables, so it is generally necessary to reduce the use of global variables, especially those that require complex initialization.
1. Try not to use global variables.
2. Use static variables to access through accessors For example: global variable int a = 5;
int b = a;
If a and b are defined in the same file, then there is no problem, and the result b is equal to 5 If a and b are defined in different files, there is no guarantee that b is also equal to 5, that is, there is no guarantee that a is initialized first In fact, except for the initialization of global objects defined in the same file, there is no guarantee of the initialization order between other global or static variables. The solution to this problem is not to use global variables directly, but instead use a wrapper function to access them, for example.
int get_a()
int get_b()
-
There are only two kinds of this, one is initialized in the definition, and the other is the first definition, which is initialized.
-
Define the initial value yourself in the program or at the beginning of the program.
-
Let's take a look at the book It's been sent to your mailbox.
-
Syntactic initialization refers to the operation of values after the corresponding allocated space is defined by the object. In C, static and global variables are set to 0 by default, the value of the initialization list is copied to the space (if it is insufficient, the rest is set to 0), and local automatic variables can not be initialized (the debugger may be implicitly initialized to other values ()."debug magic number"), for example, Microsoft C C++ Debugger will set uninitialized bytes in the stack to 0xcc by default).
Generally speaking, the initial value refers to initialization in a logical sense. In C, since the syntax of initialization is "=" followed by the initial value, "assigning the initial value" basically refers to the syntactic initialization. However, with the development of language, the meaning of "endowment" has expanded.
There are subtle differences between programming languages that have construction semantics but allow for non-initialization without compilation errors. For example, in a C++ constructor, the initialization list consisting of several member names and initialization values enclosed in parentheses is syntactically initialized (or logical, if not overridden by the value in the constructor body), while the assignment statement to the member in the constructor body is a logical initialization but not a syntactic initialization.
The throbbing of ice Error:
1.The phrase "initialize at the beginning of the program" applies only to static or global variables, not to local automatic variables. Local automatic variables are not initialized until the function is called.
2."But depending on the compiler, some compilers will automatically assign an initial value of 0 or something" - this is not the behavior defined by the implementation in the ISO IEC C language standard, if a compiler meets the standard, then the behavior is unambiguous, i.e. depending on whether the initialized object is a global object to determine whether the implicit initialization is set to 0 or not - from the following function definition, var2 should be a global variable and will be set to 0. Non-standard compilers are a different story (but I haven't seen anyone who will find fault with this).
-
Not the same.
Initialization, which only happens after the first assignment or load after the definition.
The initial value can be understood as supporting multiple uses (i.e., multiple initial values need to be assigned) for the first value given for this use.
In fact, these are all described by people, and they are all the same.
-
No, there is no difference between general variables, and it is obvious for static variables, such as:
int func()
As you can see from the above example, static variables are initialized only once, so the value of a increases with the number of calls; And b is always 11 because of the reassignment.
-
int a=12 ;Initialize, copy 0x000c to a
a =12 ;Assignment, copy 0x000c to a
1. If the initial value of the static variable is not explicitly specified when defined, it will be automatically initialized to the zero value of the corresponding type (the numeric type is 0 or; The character type is'\0'), that is, static variables can be initialized automatically (some are called implicit initialization), and static variables are initialized only once. If a value is explicitly specified when a static variable is defined, its initial value is the specified value. Initialization can only be initialized once, regardless of whether the initial value is explicitly specified at definition.
However, the value of a static variable can be modified multiple times by assigning a value.
2. Initialization and assignment are different concepts.
Static variables are initialized at compile time, and variables are assigned at function or program runtime. Static variables are initialized only once, but the value of static variables can be modified multiple times by assigning values.
The following program requires that the main function output 5 planetary numbers at the end of each cycle. Analyze the output of the following programs.
int i;
main()
void pr()
Please analyze: The pt function was also called 5 times, but the result was only one planet number, not 5 planet numbers. The different concepts of assignment of static variables and initialization of static variables are verified.
void pt()
void pk()
If the application fails to initialize normally (0xc000142) when the computer is booted, please click OK to terminate the application, and the steps to solve the problem are as follows: (Demonstration uses win10 system, and the operation of other windows versions is roughly the same). >>>More
The corporate IC card was not inserted when logging in to the invoicing system. >>>More
Turn the computer off and on or click Restart, then press and hold the Delete key, and the computer will automatically enter the BIOS. >>>More
When encountering "Application Initialization Normally ( Failed. Please click 'OK' to terminate the application. "Situation, Microsoft.NET Framework and above can solve the problem!
Friend,I've also encountered this thing.,First of all, you m3 must run and these software are installed.,It's those software in the support folder of the disc image.,If you install it, then see if you hit the mod.,Find the problem mod first.,After scanning and dealing with the problematic mod.,You have to delete "My documents Electronic Arts Sims 3. >>>More