为什么变量名不能以数字开头? [英] Why can't variable names start with numbers?

查看:222
本文介绍了为什么变量名不能以数字开头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前段时间,我正与一个新的C ++开发人员一起工作,他问一个问题:为什么变量名不能以数字开头?"

I was working with a new C++ developer a while back when he asked the question: "Why can't variable names start with numbers?"

除了一些数字可以包含文本(123456L,123456U)之外,我无法给出答案,并且如果编译器认为带有一定数量的字母字符的所有内容都是变量名,那将是不可能的.

I couldn't come up with an answer except that some numbers can have text in them (123456L, 123456U) and that wouldn't be possible if the compilers were thinking everything with some amount of alpha characters was a variable name.

那是正确的答案吗?还有其他原因吗?

Was that the right answer? Are there any more reasons?

string 2BeOrNot2Be = "that is the question"; // Why won't this compile?

推荐答案

因为一串数字既是有效的标识符又是有效的数字.

Because then a string of digits would be a valid identifier as well as a valid number.

int 17 = 497;
int 42 = 6 * 9;
String 1111 = "Totally text";

这篇关于为什么变量名不能以数字开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆