私はCプログラミングを学んでいますが、私の本には、変数とは異なり、プログラムの実行中に定数を変更することはできないと書かれています。そして、それらはリテラルとシンボリックの2つのタイプの定数です。シンボリックはかなりよく理解していると思います。しかし、リテラル定数は私を混乱させています。それが私に与えた例は
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)
誰かがこれがどのように起こるかを説明できますか、私はそれを間違っていると宣言していますか?または、通常の変数とリテラル定数の間に違いはありますか?
-ありがとう