why my const integer is strangely accepting an assignment statement or
an increment operation on it just with a warning ??!!
It should restrict me from doing that.. isn't it??
Next time, please post a small program that exhibits the problem,
along with the warning message your compiler produces.
(Copy-and-paste both the program and the message; don't attempt to
re-type them.)
There are various ways you can bypass const qualification and
*attempt* to assign a value to a const-qualified object (for example,
by using a pointer cast). Any attempt to do so invokes undefined
behavior; the compiler is not required (and typically is not able) to
diagnose the problem, but any arbitrarily bad thing can happen when
you execute the code. In the best case, your program immediately
crashes. In the worst case, it silently "works". In the *really*
worst case, it works at first, but fails catastrophically at the most
inconvenient possible moment. So don't do that.
But since you mentioned a warning, that's probably not what happened
in your case. Somebody posted a possible example:
int main(void) {
const int i;
i = 0;
}
The assignment is invalid. This is an example of a class of errors
that the standard calls "constraint violations". The standard
requires a compiler to issue a "diagnostic message", but it says very
little about what a "diagnostic message" is. In particular, the
compiler is not required to reject your program; once it's issued a
diagnostic message, it's done its job. (It's also allowed to issue
diagnostic messages for things that aren't constraint violations.)
The lesson: Don't ignore warnings.
And if you had posted your actual code, we wouldn't have had to guess,
and our responses could probably have been shorter, less numerous, and
more to the point.