Using an ampersand in scanf()

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-03-13T19:36:11Z Indexed on 2010/03/13 19:45 UTC
Read the original article Hit count: 271

Filed under:
|
|

When I compile scanf("%s", &var);, gcc sends back a warning:

warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’

however when I compile scanf("%s", var);, no warning is applied. Both pieces of code work and the book I am reading specifically says to use the ampersand, but even it doesn't in some of the examples.

My question is, should I continue to use the ampersand, even when the book doesn't specify?

© Stack Overflow or respective owner

Related posts about c

    Related posts about scanf