Why can I implicitly convert an int literal to an int * in C but not in C++?

后端 未结 4 1804
北荒
北荒 2020-12-09 15:58

I believed that in the following code, C \"automatically casts 17 to an int *\" which, as someone recently pointed out (but did not give the reasons as to why),

4条回答
  •  庸人自扰
    2020-12-09 16:20

    Yes, the casting is implicit in C, although many (all?) compilers give a warning. In C++, no implicit conversion is performed from int to int*, so the explicit cast is required.

提交回复
热议问题