xcode编写C时,指针为啥不能改变const修饰的一个常量?

ISO IEC 9899 2011(C11)标准中:6.7.3 Type qualifiersThe implementation may place a const object that is not volatile in a read-only region ofstorage. Moreover, the implementation need not allocate storage for such an object if its address is never used.If an attempt is made to modify an object defined with a const-qualified type through useof an lvalue with non-const-qualified type, the behavior is undefined.人生苦短,不要在“未定义行为”上浪费时间。PS:这类问题,实际上在 stackoverflow 上总能找到一个满意的答案。----
■网友
强行修改常量的值是UB,所以编译器很可能会直接把printf("%d\", number)优化为printf("%d\", 10)实际上编译器的确这么做了。


    推荐阅读