Why adress operator absent in string of fetching a scanf statement for example ("%s",s) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why adress operator absent in string of fetching a scanf statement for example ("%s",s)

If space is there then scanf stops reading for example:Hello World then output is Hello (any one tell how to overcome this )rather than get statement

9th Aug 2019, 3:12 AM
LOKESHA E J
LOKESHA E J - avatar
4 Answers
+ 10
String is an array of characters literals, and array name itself denote the base address of the array. In string the pointer variables itself point towards the base address of the string so address of operator is not required. String in general hold the address of the character buffer which is pointed by pointer at the base address of the character array
9th Aug 2019, 3:23 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 5
scanf is used to read input until it encounters a whitespace, newline or End Of File (EOF). "&" is used to get the address of the variable. C does not have a string type, string is just an array of characters and an array variable stores the address of first index location. by default the variable points to the base address and therefore to access base address of string there is no need to add an extra "&".
9th Aug 2019, 3:39 AM
notqueued
notqueued - avatar
+ 1
Tnx for information now my doubt cleared
9th Aug 2019, 3:32 AM
LOKESHA E J
LOKESHA E J - avatar
+ 1
Nice way u explained
9th Aug 2019, 3:42 AM
LOKESHA E J
LOKESHA E J - avatar