Programming Languages-Identifiers

Source: Internet
Author: User
What is an identifier?
Analogy life, the identifier is actually a name, your name is Zhang San, then others say Zhang San is you. For example, the Yangtze River, then others say the Yangtze River, then you will not think of the Yellow River. Then the identifier in the program, such as the variable name, you can declare (definition) at will.
Declare a variable, such as int age. It's like a container named age, which holds the int type data, and that is the name of the container, which is the identifier.
What constitutes an identifier. This is like what your name consists of, the Chinese name is generally composed of Chinese characters, and perhaps very few people will have letters.
Rules for identifiers in programs (most languages are the same, for the same reason):
1. consist of letters, numbers, underscores _ and USD $;
2. Identifiers may not be preceded by numbers;
3. You cannot use keywords as identifiers;
4. Strictly case-sensitive;
Commentary 1, letter 26 letters, including case, number 0-9, glide line _ and US knife symbol $
Explanation 2, why can not start with a number, with the addition of computer operations as an example, to join can start with a number,
int age = 20; Defines the variable age and initializes it to 20;
int 9age = 10; define variable 9age and initialize to 10
int sum = age + 9age;
int total = age + 9;
How does the computer execute it. Age + 9 is no ambiguity, the computer adds age (20) and 9 together equals 29; the computer encounters age + 9age will appear every day should not be called to the ground is not the spirit, age + 9 Why the following to add the letter, is to add 9 or to add 9age, the computer can not be identified. Just like, one day someone holding 100 dollars and 100 million yuan World Bank money, the original intention is to burn all to the deceased, but the underworld saw 100 U.S. knives do not know, only left the World Bank money, distorted your meaning. Age + 9age, the computer is not clear you are going to be age + 9, or age + 9age, so identifiers can not start with a number.
Commentary 3, you can not use the keyword to do identifiers, first what is the keyword. Keywords are identifiers that have been assigned special meanings by the system. Avoid using or not be able to use identifiers when developing a program. For example, Int,long,char in C has special meanings, and int is used to declare the shaping data. If you use int as the variable name, then when you want to declare the integer data, what are you going to use to define it, at which point you will not have int type data to use. For example, the commander is the commander of the army, but you let the commander do the soldiers on the front, when the need to make a decision on a campaign, you have not found the commander.
Commentary 4, in the world of C and Java, A and a are not born of a and grown-up a,a and A are not twins, a and a are not the same.
Therefore, do not consider age and age to be the same identifier.
C language has 32 keywords, the keyword is the system assigned a special function of the identifier, a total of 32, such as int, short, long, and so on.

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.