【发布时间】:2013-02-25 04:47:54
【问题描述】:
我正在学习 C 编程,我的书说,与变量不同,常量在程序执行期间不能更改。并且它们是两种类型的常量 Literal 和 Symbolic。我认为我非常了解 Symbolic。但是字面常量让我感到困惑。 它给我的例子是
int count = 20;
我写了这个简单的程序,我可以改变字面常量的值。
/* Demonstrates variables and constants */
#include <stdio.h>
/* Trying to figure out if literal constants are any different from variables */
int testing = 22;
int main( void )
{
/* Print testing before changing the value */
printf("\nYour int testing has a value of %d", testing);
/* Try to change the value of testing */
testing = 212345;
/* Print testing after changing the value */
printf("\nYour int testing has a value of %d", testing);
return 0;
}
它输出了这个:
Your int testing has a value of 22
Your int testing has a value of 212345
RUN SUCCESSFUL (total time: 32ms)
有人能解释一下这是怎么发生的吗,我说错了吗?或者普通变量和字面常量有什么区别?
-谢谢
【问题讨论】:
标签: c