Thread: Address of array using scanf

  1. #1
    Registered User
    Join Date
    Sep 2019
    Posts
    15

    Address of array using scanf

    can someone please explain why when we use scanf to get array input we don't have to put the & sign in front of the Var name of the array

    e.g
    char name[20];
    int id;
    printf("Enter stuid, name ");
    scanf("%d%s", &id, name);
    Why is & omitted here ? while for eg for the id i have to > &id
    why is this ??



  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    In most contexts, an array is converted to a pointer to its first element. The notable exceptions being when the array is an operand of the address-of operator & and the sizeof operator.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2019
    Posts
    15
    can you give an example of the exceptions you mention ? If possible?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I already told them to you. What kind of example are you looking for?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. comparing the address of a pointer to an array address for size
    By ridgerunnersjw in forum C Programming
    Replies: 4
    Last Post: 04-17-2020, 06:25 PM
  2. Replies: 2
    Last Post: 01-05-2019, 12:35 AM
  3. Converting an int to an address in an array
    By bommy in forum C Programming
    Replies: 16
    Last Post: 03-19-2009, 03:02 PM
  4. Array address passing help please??
    By blackCat in forum C Programming
    Replies: 9
    Last Post: 03-09-2009, 07:33 AM
  5. address of array
    By strobe9 in forum C++ Programming
    Replies: 4
    Last Post: 10-13-2003, 09:37 AM

Tags for this Thread