Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

C 变量名称 (标识符)


C 变量名称

所有 C **变量** 必须使用 **唯一名称** 进行 **标识**。

这些唯一名称被称为 **标识符**。

标识符可以是简短的名称(如 x 和 y),也可以是更具描述性的名称(age、sum、totalVolume)。

**注意:** 建议使用描述性名称以创建易于理解和维护的代码

示例

// 好的变量名称
int minutesPerHour = 60;

// 还可以,但不太容易理解 **m** 到底是什么
int m = 60;
自己试一试 »

**变量命名的通用规则** 为

  • 名称可以包含字母、数字和下划线
  • 名称必须以字母或下划线 (_) 开头
  • 名称区分大小写 (myVarmyvar 是不同的变量)
  • 名称不能包含空格或特殊字符,如 !、#、% 等。
  • 保留字(如 int)不能用作名称


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.