Not casting pointers in C can cause problems?

前端 未结 6 1711
梦谈多话
梦谈多话 2021-02-07 15:21

Yesterday I was in class, and at some point the instructor was talking about C code. He said:

What is the purpose of making a pointer cast in C? The only

6条回答
  •  太阳男子
    2021-02-07 15:41

    Casting for pointers is essential to say the compiler how to perform pointer arithmetic.

    For example if x is a character pointer pointing to memory 2001, x++ should go to 2002, but if x is an integer pointer x++ should be 2003

    so if type casting is not done for pointers compiler won't be able to perform pointer arithematic properly.

提交回复
热议问题