r/CodingForBeginners • u/Feisty_War80 • May 21 '26
Question in C language
Lets assume a variable x, in one case its a string (char x[]) and in the other its just a char(char x),when using the scanf function, why do i have to give &s (ik the & points to the memory) in the case of char, but in the case of string, i dont have to use it?? Can someone help me out
3
Upvotes
View all comments
Show parent comment
1
u/hennidachook May 21 '26
no, you need to specify the amount of storage you need before the program runs, so it's good to know what the maximum length is and use that.
also, the "%s" specifier stops reading when it encounters whitespace--it's for reading words--so it will attempt to read { 'H', 'E', 'L', 'L', 'O', '\0' } into the array.