I am a beginner and reading C primer plus. There's a place I can't understand. I know that constant can't be changed throughout the program, and when I read this:
Initializing a Variable:
...
int hogs = 21;
int cows = 32, goats =14;
int dogs, cats = 94;
...
The various integers(21, 32, 14, and 94) are integer constants. When you write a number without a decimal point and without an exponent, C recognizes it as an integer.
I was confused about what he's saying the integer constant and integer. I thought maybe he said that when you write this "int hogs = 21;", you are declaring the hogs as a constant. So I coded myself to check whether "int hogs = 21;" is or not to declare a constant:
int main()
{
int words = 3020, lines = 350;
printf("there were %d words and %d lines\n", words, lines);
words = 2;
lines = 1;
printf("change %d and %d", words, lines);
return 0;
}
It can be changed! And then I searched online, I knew that you should write this "const int hogs = 21;" to declare a constant. But what is the integer constant? what is "The various integers(21, 32, 14, and 94) are integer constants. When you write a number without a decimal point and without an exponent, C recognizes it as an integer.". It's already an integer because you have coded "int hogs =21;". I think maybe he said that if you don't declare the variable and use a number directly, like 10, the compiler will recognize the number as a integer variable. And 10 is what he said the 'integer constant'. So is that right?