How does the scanf function work in C?

前端 未结 7 1678
孤独总比滥情好
孤独总比滥情好 2020-12-06 13:48

Why do you require ampersand (&) in the scanf function. What will the output or type of error (compile or runtime) be in the following C code?



        
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 14:14

    You don't always need to use an & with scanf. What you need to do is to pass pointers. If you're new to C, you should spend some time reading the comp.lang.c FAQ:

    http://c-faq.com/

    Specifically:

    • Why doesn't the call scanf("%d", i) work?
    • Why does the call scanf("%s", s) work?

提交回复
热议问题