You declared j as const, so it's perfectly reasonable for the compiler to have put that number in a location that cannot be written to, so when you discard the const qualifier and try to edit it the operation fails. You are invoking undefined behavior by trying to do what you are doing.