我正在学习 C 编程,我的书说,与变量不同,常量在程序执行期间不能更改。并且它们是两种类型的常量 Literal 和 Symbolic。我认为我非常了解 Symbolic。但是字面常量让我感到困惑。它给我的例子是
int count = 20;
我写了这个简单的程序,我可以改变 Literal Constant 的值。
/* 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)
有人可以解释这是怎么发生的,我是不是说错了?或者普通变量和文字常量之间有什么区别?
-谢谢