Variables and declarations and definitions

Source: Internet
Author: User

Variables (Variable) are one of the most important concepts in programming languages, and variables are a named space in computer memory that can
Store a value in it, the stored value can be changed at any time, such as the Save a character ' a ' next time to save a word
Character ' B ', because the value of the variable can be changed at any time so it is called a variable.

declarations in C (Declaration) have three types of variable declarations, function declarations, and type declarations. If a variable or function is

A declaration requires the compiler to allocate storage space for it, which can also be called definition, so the definition is a declaration.

Declaring a type is not allocating storage space, but it seems to be called "type definition" sounds good, so in this book "type definition" and "

A type declaration "represents the same meaning. Declarations are similar to statements, but they end with a number, but the syntax for declaring and statements is different

, the statement can only appear in {} brackets, and the declaration may appear in {} or all outside {}.

There is a certain limit to the name of the variable, C must be preceded by a letter or underscore _ (underscore), followed by
Do a letter, a number, an underscore, but no other characters. These are, for example, valid variable names: ABC, __abc__, _123.
But these are illegal variable names: 3ABC, ab$. In fact, this rule applies not only to variable names, but also to all
The syntax elements of the sequencer name, such as the function names, macro definitions, struct member names, and so on, which are called in the C language.
identifier (Identifier).
It is also important to note that a char, int, float, double, and so on, which represent a type, conform to the above rules but cannot be used as an identifier.
Some words in the C language have special meanings and are not allowed as identifiers, which are called Keywords (Keyword) or reserved words
(Reserved Word). Text editors that are typically used for programming will highlight (Highlight) These keywords, so only
Be careful not to use it as an identifier, usually. The key words stipulated by C99 are:
Auto break case Char const continue default do double
else enum extern float for goto if inline int long
Register restrict return short signed sizeof static struct switch typedef
Union unsigned void volatile while _bool _complex _imaginary


It is also important to note that identifiers that begin with an underscore should generally be avoided, with an identifier that begins with an underscore
and c keyword conflicts are legitimate, but often by the compiler as a function extension, C standard library also defines a lot of
An identifier that begins with an underscore, so unless you are particularly clear about the compiler and the C standard library, you should generally avoid using this identifier.
Avoid naming conflicts.


  Remember: To understand a concept is not to memorize the definition of the line, we must understand its denotation and connotation, that is, what is the case
In this concept, what does not belong to this concept, what is the case although it is a general recommended practice (best
Practice) is to try to avoid this situation, which is really understood.

Variables and declarations and definitions

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.