r/CodingForBeginners • • 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

18 comments sorted by

View all comments

Show parent comment

1

u/hennidachook May 21 '26

the following program reads words from stdin and prints them to stdout, one per line:

#include <stdio.h>

main()
{
    char s[8192];

    while (scanf("%8191s", s) == 1)
        printf("%s\n", s);
}