Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include <stdio.h>
    int main(){ 

    char st[55];


    printf("Enter name \n");
    scanf("%c\n",st);<pre>// why we don'nt need to add & in it 



return 0;
}

What I have tried:

I tried to take user from input without & in a string
Posted
Updated 9-Jun-22 1:33am

When you pass an array as an argument in C or C++, it is treated as a pointer to the beginning of the array, so passing st here is basically the same as passing &st[0].
 
Share this answer
 
Quote:
Why not use ampersent

Because the compiler understand what you want to do, and it does the necessary adjustments automatically.
The compiler understands that you want to use a pointer,
scanf - C++ Reference[^]
C library function - scanf()[^]
 
Share this answer
 
The C language specification says that the name of an array is a pointer to the first element of that array - so passing st is the equivelant of typing &(st[0]) but a lot easier to read!
 
Share this answer
 
v2
Get yourself a copy of The C Programming Language - Google Search[^] where all such issues are clearly explained.

As suggested last week.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900