Computer Programming 简明教程
Computer Programming - Keywords
到目前为止,我们已经介绍了两个重要的概念,即变量及其数据类型。我们讨论了如何使用 int 、 long 和 float 来指定不同的数据类型。我们还学习了如何命名变量以存储不同的值。
So far, we have covered two important concepts called variables and their data types. We discussed how to use int, long, and float to specify different data types. We also learnt how to name the variables to store different values.
尽管不需要单独设置这一章节,因为保留关键字是基本编程语法的组成部分,但是为了方便理解,我们将其设置为数据类型和变量之后的单独部分进行说明。
Though this chapter is not required separately because reserved keywords are a part of basic programming syntax, we kept it separate to explain it right after data types and variables to make it easy to understand.
与 int、long 和 float 一样,C 编程语言还支持许多其他关键字,我们将它们用于不同的目的。不同的编程语言提供不同的保留关键字集,但所有编程语言中有一条重要且共同的规则,即我们不能使用保留关键字来命名我们的变量,这意味着我们不能将变量命名为 int 或 float ,而只能使用这些关键字来指定变量数据类型。
Like int, long, and float, there are many other keywords supported by C programming language which we will use for different purpose. Different programming languages provide different set of reserved keywords, but there is one important & common rule in all the programming languages that we cannot use a reserved keyword to name our variables, which means we cannot name our variable like int or float rather these keywords can only be used to specify a variable data type.
例如,如果您尝试将任何保留关键字用作变量名称,那么您将收到语法错误。
For example, if you will try to use any reserved keyword for the purpose of variable name, then you will get a syntax error.
#include <stdio.h>
int main() {
int float;
float = 10;
printf( "Value of float = %d\n", float);
}
当您编译上面的程序时,将产生以下错误:
When you compile the above program, it produces the following error −
main.c: In function 'main':
main.c:5:8: error: two or more data types in declaration specifiers
int float;
......
现在让我们为我们的整数变量赋予一个合适的名称,那么上面的程序应该能够顺利编译和执行:
Let’s now give a proper name to our integer variable, then the above program should compile and execute successfully −
#include <stdio.h>
int main() {
int count;
count = 10;
printf( "Value of count = %d\n", count);
}
C Programming Reserved Keywords
这是一个包含 C 编程语言支持的几乎所有关键字的表格 −
Here is a table having almost all the keywords supported by C Programming language −
auto |
else |
long |
switch |
break |
enum |
register |
typedef |
case |
extern |
return |
union |
char |
float |
short |
unsigned |
const |
for |
signed |
void |
continue |
goto |
sizeof |
volatile |
default |
if |
static |
while |
do |
int |
struct |
_Packed |
double |
Java Programming Reserved Keywords
这是一个包含 Java 编程语言支持的几乎所有关键字的表格 −
Here is a table having almost all the keywords supported by Java Programming language −
abstract |
assert |
boolean |
break |
byte |
case |
catch |
char |
class |
const |
continue |
default |
do |
double |
else |
enum |
extends |
final |
finally |
float |
for |
goto |
if |
implements |
import |
instanceof |
int |
interface |
long |
native |
new |
package |
private |
protected |
public |
return |
short |
static |
strictfp |
super |
switch |
synchronized |
this |
throw |
throws |
transient |
try |
void |
volatile |
while |
Python Programming Reserved Keywords
这是一个包含 Python 编程语言支持的几乎所有关键字的表格 −
Here is a table having almost all the keywords supported by Python Programming language −
and |
exec |
not |
assert |
finally |
or |
break |
for |
pass |
class |
from |
|
continue |
global |
raise |
def |
if |
return |
del |
import |
try |
elif |
in |
while |
else |
is |
with |
except |
lambda |
yield |
我们知道你无法记住所有这些关键字,但我们已将其列出供你参考并解释 reserved keywords 的概念。因此,在给变量命名时请务必小心,不应使用该编程语言的任何保留关键字。
We know you cannot memorize all these keywords, but we have listed them down for your reference purpose and to explain the concept of reserved keywords. So just be careful while giving a name to your variable, you should not use any reserved keyword for that programming language.