如何以变量方式使用常量? [英] How is it possible to use a constant in a variegate way?

查看:76
本文介绍了如何以变量方式使用常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我喜欢在变量中使用几个常量来改变常量的名称。

进一步的文字显示我的徒劳尝试:


#define KONST1 13 / * Konstanten festlegen * /

#define KONST2 7

#define KONST2 47

main(){


int c = getchar(),i; / * Variablen definieren und

initialisieren * /

for(i = 1,i< = 3,i ++){/ *EinfügenvonASCii Zeichen * /

putchar(c + KONSTi);

c = getchar();

}

}

我是C的新手,我希望这个问题不要讨厌。


感谢您的支持!



I like to use couple of constant in comination with an variable to
change the name of the constant.

The further text show my vainly try:

#define KONST1 13 /*Konstanten festlegen*/
#define KONST2 7
#define KONST2 47

main() {

int c = getchar(), i; /*Variablen definieren und
initialisieren*/
for (i = 1, i <= 3, i++) { /*Einfügen von ASCii Zeichen*/
putchar(c+KONSTi);
c = getchar();
}
}

I am a newbie in C and I hope this question is not to nasty.

Have thanks for your kindly support!

推荐答案

Zottel写道:
Zottel wrote:

>

我喜欢使用几个常量变量为

更改常量的名称。


进一步的文字显示我徒劳的尝试:


#define KONST1 13 / * Konstanten festlegen * /

#define KONST2 7

#define KONST2 47
>
I like to use couple of constant in comination with an variable to
change the name of the constant.

The further text show my vainly try:

#define KONST1 13 /*Konstanten festlegen*/
#define KONST2 7
#define KONST2 47



你不应该先重新定义一个宏而不先解开它。

You shouldn''t redefine a macro without undefining it first.


main(){
main() {



main返回int。

main returns int.


>

int c = getchar(),i; / * Variablen definieren und

initialisieren * /
>
int c = getchar(), i; /*Variablen definieren und
initialisieren*/



糟糕的风格,不要在同一个上混合变量赋值和声明
行。通常建议每行保留一个声明。

Bad style, don''t mix variable assignment and declarations on the same
line. It''s often recommended to keep to one declaration per line.


for(i = 1,i< = 3,i ++){/ *EinfügenvonASCii Zeichen * /
for (i = 1, i <= 3, i++) { /*Einfügen von ASCii Zeichen*/



逗号应该是分号。

The commas should be semicolons.


putchar(c + KONSTi);
putchar(c+KONSTi);



不,你不能这样做。也许你想把KONST定义为数组?


-

Ian Collins。

No, you can''t do this. Maybe you want to define KONST as an array?

--
Ian Collins.


Zottel写道:
Zottel wrote:

>

我喜欢使用几个常量与变量结合使用

更改常量的名称。


进一步的文字显示我徒劳地尝试:


#define KONST1 13 / * Konstanten festlegen * /

#define KONST2 7

#define KONST2 47
>
I like to use couple of constant in comination with an variable to
change the name of the constant.

The further text show my vainly try:

#define KONST1 13 /*Konstanten festlegen*/
#define KONST2 7
#define KONST2 47



非法。 KONST2已定义。


-

圣诞快乐,快乐的Hanukah,新年快乐

Joyeux Noel,Bonne Annee。

Chuck F(cinefalconer at maineline dot net)

< http://cbfalconer.home.att.net>

-

通过 http://www.teranews.com <上的免费Usenet帐户发布/ a>

illegal. KONST2 is already defined.

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com


#define KONST1 13 / * Konstanten festlegen * /
#define KONST1 13 /*Konstanten festlegen*/

#define KONST2 7

#define KONST2 47
#define KONST2 7
#define KONST2 47



非法。 KONST2已定义。


illegal. KONST2 is already defined.



对不起应该是一个错误

#define KONST1 13 / * Konstanten festlegen * /

#define KONST2 7

#define KONST3 47

Sorry a mistake it should be
#define KONST1 13 /*Konstanten festlegen*/
#define KONST2 7
#define KONST3 47


这篇关于如何以变量方式使用常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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