Casting int pointer to char pointer causes loss of data in C?

后端 未结 7 2000
梦如初夏
梦如初夏 2020-12-19 17:26

I have the following piece of code:

#include 
#include 
int main(int argc, char *argv[])
{
  int n = 260; 
  int *p = &n;
         


        
7条回答
  •  时光取名叫无心
    2020-12-19 17:53

    Your problem is the assignment *pp = 0; You're dereferencing pp which points to n, and changing n. However, pp is a char pointer so it doesn't change all of n which is an int. This causes the binary complications in the other answers.

提交回复
热议问题