Hi, everyone.
I have written the following program, which compiles and runs on gcc/Ubuntu. Is it legal C?
Code:int main() { const int a = 1; int* b = &a; *b = 2; return 0; }
Hi, everyone.
I have written the following program, which compiles and runs on gcc/Ubuntu. Is it legal C?
Code:int main() { const int a = 1; int* b = &a; *b = 2; return 0; }
Do you get this warning?
warning: initialization discards qualifiers from pointer target type
If you try to modify an object declared const, you're into undefined behaviour territory.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.