int age;
char name[10];
scanf("%d", &age);
scanf("%s", name);
In first scanf function we use '&' symbol before age, but in second scanf we don’t use '&'
as it is a char array. Can anybody tell me why is so?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Under most circumstances, an expression of type “N-element array of
T” will be converted to (“decay”) to type “pointer toT“, and the value of the expression will be the address of the first element in the array.When you write
the expression
namehas type “10-element array ofchar“; by the rule above, it is converted to type “pointer tochar“, and its value is the same as&name[0]. Soscanfreceives a pointer value, not an array value.The exceptions to this rule are when the array expression is an operand of the
sizeof,_Alignof, or unary&operators, or is a string literal being used to initialize another array in a declaration.Note that the expressions
nameand&namewill give you the same value (the address of the first element of the array is the same as the address of the array), but their types will be different;namewill have typechar *, while&namewill have typechar(*)[10], or “pointer to 10-element array ofchar“.