What is the difference between float pointer and int pointer address?

后端 未结 3 1420
醉话见心
醉话见心 2021-01-02 09:20

I tried to run this code,

int *p;
float q;
q = 6.6;
p = &q;

Though it will be a warning, but i think &q and p

3条回答
  •  盖世英雄少女心
    2021-01-02 09:31

    You're getting undefined behaviour, because you're passing the wrong types to printf. When you tell it to expect a float, it actually expects a double - but you pass an int.

    As a result it prints the wrong information, because printf relies entirely on the format string to access the arguments you pass it.

提交回复
热议问题