address passing in scanf but not in printf [duplicate]

China☆狼群 提交于 2021-02-16 09:28:12

问题


Possible Duplicate:
Why scanf must take the address of operator

Why do we pass the variable in the case of printf(), whereas the address of the variable in the case of scanf()? why to pass address in scanf


回答1:


why to use '&' in scanf( ) but not in printf( )

'printf'()' only need the values in order to output them. 'scanf()' stores values, so it needs a place to store them. This is done by providing the addresses (in pointers) of where to store the values.




回答2:


With scanf you want the callee to modify the variable that's why you pass it by reference, if you pass it by value like with scanf you would not have access to the variables address to modify its contents.



来源:https://stackoverflow.com/questions/12102753/address-passing-in-scanf-but-not-in-printf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!