一些问题 [英] Some Questions
问题描述
你好,
我有一些问题。
1)常量表达式包含字符串文字吗?例如,
" hello,world"一个常数表达式?
2)int i = 0;是赋值运算符的等号还是只有一个
符号? (我认为最后一个是正确的)
3)数组是变量吗?例如:
int i = 0; / *`i''是变量* /
char * cPtr; / *`cPtr''是变量* /
int a [10]; / *是'a''变量? * /
K& R(2ed)说(第5.3段;第99页):[...]变量的值
[ ...]类型数组[...]。
所以我认为数组是一个变量。
谢谢
hello,
i have some questions.
1) do constant expressions include string literals? for example, is
"hello, world" a constant expression?
2) int i = 0; is the equal sign the assignment operator or is it only a
symbol? (i think the last one is correct)
3) is an array a variable? for example:
int i = 0; /* `i'' is a variable*/
char *cPtr; /* `cPtr'' is a variable */
int a[10]; /* is `a'' a variable? */
K&R (2ed) says (paragraph 5.3; page 99): "[...] the value of a variable
[...] of type array [...]".
so i think an array is a variable.
thanks
推荐答案
文章< 44 *********************** @ reader2 .news.tin.it>,fctk< - >写道:
In article <44***********************@reader2.news.tin.it>, fctk <-> wrote:
1)做常量表达式包括字符串文字?例如,
hello,world一个恒定的表达?
一般情况下不一样。然而,它是一个地址常量,可以在初始化器的上下文中使用
。
2)int i = 0;赋值运算符是等号还是只是一个
符号? (我认为最后一个是正确的)
这是语义问题,但问问自己语法
是否允许(比如说)int i - = 5;确定语法
是否允许赋值运算符。
3)数组是变量吗?例如:
int i = 0; / *`i''是变量* /
char * cPtr; / *`cPtr''是变量* /
int a [10]; / *是'a''变量? * /
1) do constant expressions include string literals? for example, is
"hello, world" a constant expression?
Not generally. It is, however, an address constant, which can be
used in the context of initializers.
2) int i = 0; is the equal sign the assignment operator or is it only a
symbol? (i think the last one is correct)
That''s a matter of semantics, but ask yourself whether the syntax
would permit (say) int i -= 5; to determine whether the syntax
permits assignment operators in general.
3) is an array a variable? for example: int i = 0; /* `i'' is a variable*/
char *cPtr; /* `cPtr'' is a variable */
int a[10]; /* is `a'' a variable? */
C89标准没有变量:它有对象,其中一些是可修改的,有些是不可修改的。数组不是可修改的b $ b,但数组元素是可修改的。在上面的例子中,
i,cPtr和a都是标识符。
-
它是否有任何可能的东西可以这么说,看,这是新的吗?它已经过时了,这已经是我们面前的了。 - 传道书
The C89 standard does not have variables: it has objects, some of
which are modifiable and some of which are not. Arrays are not
modifiable, but array elements are modifiable. In your above examples,
i, cPtr, and a are all "identifiers".
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes
Walter Roberson ha scritto:
Walter Roberson ha scritto:
文章< 44 ************** *********@reader2.news.tin.it>,fctk< - >写道:
In article <44***********************@reader2.news.tin.it>, fctk <-> wrote:
2)int i = 0;赋值运算符是等号还是只是一个
符号? (我认为最后一个是正确的)
2) int i = 0; is the equal sign the assignment operator or is it only a
symbol? (i think the last one is correct)
这是语义问题,但要问问自己语法
是否允许(比方说)int i - = 5;确定语法
是否允许赋值运算符。
That''s a matter of semantics, but ask yourself whether the syntax
would permit (say) int i -= 5; to determine whether the syntax
permits assignment operators in general.
编译器不允许:int i - = 5;所以我猜一个
变量定义中的等号不是运算符,而是一个符号(例如语句结尾处的
分号)。
the compiler does not permit: int i -= 5; so i guess the equal sign in a
variable definition is not an operator, but a sign (such as the
semicolon at the end of statements).
3)数组是变量吗?例如:
3) is an array a variable? for example:
int i = 0; / *`i''是变量* /
char * cPtr; / *`cPtr''是变量* /
int a [10]; / *是'a''变量? * /
int i = 0; /* `i'' is a variable*/
char *cPtr; /* `cPtr'' is a variable */
int a[10]; /* is `a'' a variable? */
C89标准没有变量:它有对象,有些是可修改的,有些则不是。数组不可修改,但数组元素是可修改的。在上面的示例中,
i,cPtr和a都是标识符。
The C89 standard does not have variables: it has objects, some of
which are modifiable and some of which are not. Arrays are not
modifiable, but array elements are modifiable. In your above examples,
i, cPtr, and a are all "identifiers".
但我们可以同意变量。是一个可修改的对象,而
常数是一个可修改的对象。是一个不可修改的对象。所以数组是一个常量,而
数组元素是变量。
在前面的例子中,`i'',`cPtr''和`a ''是一个标识符,它指的是(按顺序)一个变量,一个变量,一个常量。
无论如何,如果我编译下面的小程序:
int main(无效){
int a [10];
返回0;
} $ / $
i得到以下警告:
test.c:在函数`main'':
test .c:2:警告:未使用的变量`a''
请注意变量这个词......
i' '有点困惑。
but we can agree that a "variable" is a modifiable object, while a
"constant" is a non-modifiable object. so an array is a constant, while
array elements are variables.
in my previous example, `i'', `cPtr'' and `a'' are identifiers which refers
to (in order) a variable, a variable, a constant.
anyway if i compile the following little program:
int main(void) {
int a[10];
return 0;
}
i get the following warning:
test.c: In function `main'':
test.c:2: warning: unused variable `a''
please notice the word "variable"...
i''m a bit confused.
文章< 44 *********************** @ reader2 .news.tin.it>,fctk< - >写道:
In article <44***********************@reader2.news.tin.it>, fctk <-> wrote:
Walter Roberson ha scritto:
无论如何,如果我编译以下小程序:
int main(void){
int a [10];
}
i得到以下警告:
test.c:在函数`main'':
test.c:2:警告:未使用的变量`a ''
请注意变量这个词......
我有点困惑。
在这种情况下,C编译器不需要发出消息,所以
它们发出的任何消息都不需要在语义上准确。
但我们可以同意变量。是一个可修改的对象,而
常数是一个可修改的对象。是一个不可修改的对象。
Walter Roberson ha scritto:
anyway if i compile the following little program: int main(void) {
int a[10];
return 0;
} i get the following warning: test.c: In function `main'':
test.c:2: warning: unused variable `a'' please notice the word "variable"... i''m a bit confused.
C compilers are not required to emit a message in that case, so
any message they do emit need not be semantically accurate.
but we can agree that a "variable" is a modifiable object, while a
"constant" is a non-modifiable object.
int main(void){
const int i = 0;
返回0;
}
int main(void) {
const int i = 0;
return 0;
}
这篇关于一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!