Home  >  Article  >  Backend Development  >  What does an identifier in C language consist of?

What does an identifier in C language consist of?

青灯夜游
青灯夜游Original
2022-11-23 17:55:417547browse

In C language, identifiers consist of letters (A~Z and a~z), numbers (0~9), and underscores (_), and the first character must be a letter or underscore, and cannot Begin with any other character or number; identifiers are case-sensitive, uppercase and lowercase letters are considered different characters, and identifiers cannot be keywords.

What does an identifier in C language consist of?

The operating environment of this tutorial: windows7 system, c99, Dell G3 computer.

Identifiers in the C language are composed of

. In high-level computer languages, they are used to identify variables, symbolic constant names, functions, arrays, Valid character sequences for naming types etc. are collectively called identifiers.

Identifier can be simply thought of as a name, used to identify variable names, constant names, function names, arrays, etc.

Variable names a, b, c, symbolic constant names PI, Pai, function names printf, scanf, etc. are all identifiers.

In C language, the identifier can be customized , but certain rules need to be followed.

The C language stipulates that an identifier can be a string consisting of letters, numbers, and underscores (A~Z, a~z, 0~9, _), and the first character must be a letter or underline.

(1) Identifier can only start with English uppercase and lowercase letters, and underscore (_) , and cannot start with any other characters or numbers .

For example, the following is an incorrect example:

int %a;//错误,标识符不能以符号开头
int 8C[8];//错误,不能以数字开头

(2) The identifier can only contain English uppercase and lowercase letters, underscores and Arabic numerals , but cannot start with an Arabic numeral .

int a8;//正确
int _adf589S_5;//正确

(3)IdentifierCase-sensitive

In C language, uppercase letters and lowercase letters are considered different characters, Therefore, the identifiers expressed by ABC and abc are different (Acd and acd, caDd and cadd, _8Fc9 and _8fc9 are all different identifiers).

(4)Identifier cannot be a keyword.

int float;//错误,float是关键字。
int Float;//正确

(5)ANSI standard stipulates that the identifier can be of any length , but the external name must be uniquely distinguishable by at least the first 6 characters, and no case sensitive. This is because some compilers (such as MS C for the IBM PC) only recognize the first 6 characters.

In addition to these hard rules, it is best to name identifiers with specific meanings to facilitate observation, reading, and maintenance.

//定义某长方体的长度、宽度和高度
int a;//高度
int b;//宽度
int c;//高度

can be changed to the following definition:

int c_Long;
int c_Width;
int c_Height;

Keywords in C language

C language does not allow the definition of variables The name is a keyword used by the C language.

Type

Keywords

Description

Data type keyword

char

Character type

short

Short integer type

int

Integer type

long

Long integer type

float

Single precision floating point type

double

Double precision floating point type

signed

yes Symbol type

unsigned

Unsigned type

enum

Enumeration type

struct

Structure type

union

Union type

void

Empty type

Control statement key Words

if

Conditional judgment statement

else

Conditional judgment statement

for

Loop statement

do

Loop statement

while

Loop statement

switch

Select branch statement

break

End loop

continue

Skip the current loop

case

Select branch statement

default

Default branch statement

goto

Unconditional jump statement

return

Return statement

Storage type keyword

extern

External declaration reference

static

static type

auto

##Auto type

register

Register type

main

Main function name

Other keywords

sizeof

Calculation type capacity

const

Constant type

typedef

Define alias

volatile

Cancel compiler optimization and do not use cache

C language provides these keywords to design programs, then, we are When defining a variable name (identifier), it cannot be the same as the keyword provided by the C language.

Related recommendations: "C Video Tutorial"

The above is the detailed content of What does an identifier in C language consist of?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn