Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 989527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:48:25+00:00 2026-05-16T05:48:25+00:00

Possible Duplicate: confusion in scanf() with & operator Why we need a & in

  • 0

Possible Duplicate:
confusion in scanf() with & operator

Why we need a & in scanf for inputting integer and why not for characters.
Do the & in scanf refers to merory location while getting input.

Eg:-

main()
{
int a;
char c;

scanf("%d",&a);
scanf("%c"c);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:48:26+00:00Added an answer on May 16, 2026 at 5:48 am

    For each conversion specifier, scanf() expects the corresponding argument to be a pointer to the proper type: %d expects an argument of type int *, %f expects an argument of type double *, %c and %s both expect an argument of type char *, etc.

    The difference between %c and %s is that the former tells scanf() to read a single character and store it in the location specified by the corresponding argument, while the latter tells scanf() to read multiple characters until it sees a 0-valued character and store all those characters in the buffer starting at the location specified by the argument.

    You need to use the & operator on your arguments if they are not already of pointer type. For example:

    int x;
    int *px = some_valid_memory_location_such_as_&x;
    char c;
    char *pc = some_valid_memory_location_such_as_&c;
    ...
    scanf("%d", &x); // x is not a pointer type, so we must use the & operator
    scanf("%d", px); // px is a pointer type, so we don't need the & operator
    scanf("%c", &c); // etc.
    scanf("%c", pc); // etc.
    

    Where things get confusing is reading strings of characters (using the %s conversion specifier):

    char buf[SIZE];
    scanf("%s", buf);    // expression 'buf' *implicitly* converted to pointer type
    

    Why don’t we need the & operator in this case? It has to do with how C treats array expressions. When the compiler sees an expression of array type (such as buf in the scanf() call), it will implicitly convert the expression from type N-element array of T to pointer to T, and set its value to the address of the first element in the array. This value is not an lvalue — it cannot be assigned to (so you can’t write something like buf = foo). The only exceptions to this rule are when the array expression is an operand of either the sizeof or & operators, or if the array expression is a string literal being used to initialize another array:

    char *p = "This is a test";  // string literal implicitly converted to char *,
                                 // string *address* written to p
    char a[] = "This is a test"; // string literal not implicitly converted,
                                 // string *contents* copied to a
    

    In short, the expression buf is implicitly converted from type char [SIZE] to char *, so we don’t need to use the & operator, and in fact the type of the expression &buf would be pointer to SIZE-element array of char, or (*)[SIZE], which is not what scanf() expects for the %s conversion specifier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: Do I really need to encode '&' as ' &' ? I
Possible Duplicate: JavaScript BlockStatement confusion Why does {10 + '1'} + 10 equal 10?
Possible Duplicate: Absolute path & Relative Path This is a very basic question, but
Possible Duplicate: Python list confusion I've got one little question about Python lists: Why
Possible Duplicate: Benefits of inline functions in C++? I have a confusion regarding the
Possible Duplicate: C++11 rvalues and move semantics confusion What I think is correct is
Possible Duplicate: Generating random integer from a range I just started learning C++ and
Possible duplicate Hello all. I have confusion in drop query that how actually it
Possible Duplicate: Do you ever need to specify javascript: in an onclick? To execute

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.