Hello Board,

I hope my questions isn't too silly. But I'm reading a book learn C in 21 days, it's a bit dated but a friend recommended it. I'm on day three where it focuses on variables. Although a part of it has got me very confused.

At one point, after describing the types of variables, it goes right in to initializing a variable right on the same line for instance:

int count = 0;

or

double percent = 0.01;

Easy enough I thought. Then I read on and it starts on constants, and specifically literal constants. It then says a literal constant can be expressed as:

int count = 20;

or

float tax_rate = 0.28;

The book goes on to explain that a constant is a value that cannot be changed during program execution.

But my question is this, what is the difference between those two examples? Defining a variable and defining a literal constant look EXACTLY the same!!! How does the compiler know the difference? How does the programmer know the difference!?!

The only tiny glimmer of difference I seem to be able to segment the two with is the fact that a variable would be defined outside the main() function, and a literal constant be defined inside any function. Whats stopping me from re-assigning a value to say tax_rate once I set the value?!

Whats the deal?

Thanks!