Why is the ampersand not required in case of reading a string in C language? scanf("%s",stringname);


Solution Required
SANGAMES KUMAR.B.B.A
0 3 326
1 year ago

Why is the ampersand not required in case of reading a string in C language? scanf("%s",stringname);

MOUNICA N
3 7 493
1 year ago

String is an array of characters. Array name itself denotes the base address of the array, where arr_name and &arr_name both are same. Hence, the string name not requires any ampersand before it in scanf.
Harish.V
2 7 1009
1 year ago

& is used in scanf to store the value directly into address of the variable but when it comes to character array(character pointer) the pointer variable itself denotes the base address of the string so & is not required for string
R ANUSHA
0 0 125
1 year ago

&= address of operator. String in general holds the address of a character buffer. But 'int' and other kinds of datatypes usually allocate a block of memory for their variables. Thus in case of 'int' and other datatypes it is necessary to specify the address of(&) the variable to get the value during run time(i.e in scanf statement).But in case of string it already specifies the address for its variable so it is not necessary to use '&' in the scanf statement for a string variable.
KALI
1 3 975
1 year ago

Because string already stores the address of its variable. So we don't need &.
BHAVITHIRA.D
0 0 71
1 year ago

In case of a string (character array), the variable itself points to the first element of the array in question. Thus, there is no need to use the '&' operator to pass the address.
Rangeeshar
0 3 150
1 year ago

You can see image for clear explanation.

Subasree G
0 1 344
11 months ago

String is actually an array of characters. For denoting array of characters & is not required as it points to the address of the variable directly . Rather for variable with any other type & is used to assign the value directly to its address.
Kowsalya.S
0 0 107
2 months ago

the variable itself points to the first element of the array