Programming languages-Constants and variables

Source: Internet
Author: User
Tags constant

constants, which are immutable data in any data type during program execution.
For example, the renminbi in your life, 5 yuan banknotes, will not become 50 or 500 yuan in any of the scenes you use.
Programming is code and computer warfare, the data type is the code of the various classes, as long as the code camp, must belong to a certain class. Constants include integer constants, floating-point constants, character constants, and, as long as the class (data type) that participates in the war, is allowed to appear as a constant.
For example: 123,34.6, ' A ' does not change the data. For example, you are a soldier, you go to 1 even you are a soldier, go to n even, you are a soldier, you are a constant. For example, boiled water, in the cup is boiled, in the basin is boiled water, in the river or boiled.

Variable, the amount of size that can be changed in any data type during program execution.
Water Cup, water Cup in the empty Cup (0) and full Cup (10), can be installed in any capacity of water, this time pour 1mL of water, the next pour 8mL of water and so on, you can change the size of the data, but it is not changing the water cup is always installed is water (data type);
The gas tank is filled with gas, the amount can change, but the gas is canned by the gas (data type) cannot be changed.
Variable definition: Data type variable name;
Double water;
Double is like water (data type), water is like Water cup (variable name), how much water to fill.
Water = 10.0;
This time the water is 10.0, then whether it can be changed. As long as the cup is large enough, you can (can change) how much water you want to load.
We can add 10.0 on the basis of 10.0, then water=20.0;
We can throw the 20.0 away and pour it directly into 10000.0, at which point water=10000.0.
where = means assignment, assign 20.0 to water, at this time water is 20.0, you can use water as 20.0.

int age; Declares a variable of the int data type, the variable name is age. Like we find a gold box that can be filled with int data, the name of the Golden box is age, how many coins do you want to throw into the gold box, then age equals how many?

When participating in a war, you first need to know what you are, and only determine what kind of soldier you are, and how you can get into the war scene and how to fight.

What is the function of the variable? Cups are used for water, gold boxes for gold, and variables. Used to store data. Within the allowable range, you want it to be a few, it's just a few.

Variable assignment: variable name = data.

For example, in life, you have a water cup, but the water cup is not water. You have a piggy store with no money in it. It's like you declare (define) a variable, but it's not assigned (water in the water Cup, money in the money jar).

Double money; declares a double type variable with a variable name of money, but it does not store the data.

Money = 9999.9; now assign a value of 9999.9 to Money, put $9999.9 into the pot, and a $9999.9 in the pot, when the 9999.9来 is used.

variable is assigned multiple times, then the value of the variable is the data.

such as int age;

Age = 10;

Age = 12;

age = 15;

So how much age should it be at this time?

This kind of scenario is like a supermarket locker, everyone to buy things before their own things, leave to take away, later people save their own things, leaving the time to take away, the variables as the locker, each time the storage of things, the front of the things will be taken away, will only leave their own things, so every assignment, The variable uses the current data without using the original data.

age=10; age is assigned a value of 10 at this time.

10 of the age=12;age is emptied, at which time the value of age is 12;

12 of the Age=15;age is emptied, at which time the value of age is 15;

So the data for the variable is the last assignment.


Variable initialization: The first assignment of a variable.

Variables are stored in the process of running the data, it is similar to the container, the storage of certain types of data, water cups inside the water, passbook deposit.

int money; declares an int type variable, and the variable name is money.

Money = 10000; Assigns a value of 10000 to the variable money. This is the initialization of the variable money.

Is it possible to define a variable and assign a variable to the same value?

Yes, it's like, you go to the bank to run a bank card, but also to bank cards to save the same.

can be written as int money = 100000; you have a card and you save 10000. That is, you declare an int-type variable, and assign a value of 10000.

You can not declare the variable type without declaring it directly. For example, acount = 1; For languages like C and Java, it is not possible, what is 1000 due, water, gas, plane, tank, computer do not know. A variable must first declare (define) a good data type before it can be used. You have to be clear about what class you are in, and you will be assigned what task.


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.