c - 如何在 "variable name"中使用空格?

标签 c string variables

我有一个非常简单的问题,但我刚刚开始学习 C。如果我能得到一些帮助,我将不胜感激,因为我正在尝试了解语法在该语言中的工作原理。

我想做的就是这样

    int Score1, Score2, "Final Score";

我得到的错误信息是这样的:

    error: expected identifier or '(' before string constant

最佳答案

通常(在 C 中肯定如此),变量名必须是有效的标识符1 并且不能包含空格或引号。

考虑将变量命名为 finalScorefinal_score


1 The C Programming Language (K&R) 中简要给出了标识符的语法, A.2.3 标识符:

An identifier is a sequence of letters [a-z, A-Z, _] and digits [0-9]. The first character must be a letter; the underscore _ counts as a letter ..

关于c - 如何在 "variable name"中使用空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25734411/

相关文章:

在 C 中聊天服务器客户端。使用线程还是进程?

c - 指针的按位算术是否定义了行为?

c# - 将数字字符串扩展为单个数字

python - 如何一次输入多个浮点变量

ios - 挣扎于引用变量(Swift)

javascript - JS : why this object property won't work and it only works if I put it inside one of the methods as a variable?

c - 使用 OpenSSL 生成 RSA key 的段错误

c - 释放二维字符数组

python - 如何仅在python中比较两个字符串与某些字符

javascript - 如何设置数组中的字符串显示 : none? JavaScript