[Solved] How to understand the following statement: “Assigning a value to a symbolic constant in an executable statement is a syntax error” [closed]


If you’re asking what I think you’re asking, here’s an example in C#:

const int numPeople = 10;
numPeople = 20 + 15;

The whole idea of a symbolic constant is just that – it’s a constant. If you could assign a value to a symbolic constant, it wouldn’t be a constant, it would be a variable (which is why the above code won’t compile).

In this case, numPeople is a symbol representing the constant 10. It’s a named constant in effect. By way of contrast, 20 and 15 are literal constants.

In C and C#, symbolic constants and literal constants should have the same effect in code – it’s literally just a substitution. Effectively, numPeople does not exist at runtime, it’s just a compile-time construct. So the last line of the above code is semantically equivalent to:

10 = 20 + 15;

which clearly makes no sense.

I wouldn’t exactly call this a “common” programming error, by the way, but I guess it does happen.

solved How to understand the following statement: “Assigning a value to a symbolic constant in an executable statement is a syntax error” [closed]