String in "c".
- char ch[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
- Program 1 :-
- Output :-
- Explanation :-
You can use the scanf() function to read a string. The scanf() function reads the sequence of characters until it encounters whitespace (space, newline, tab, etc.).
Even though Pavan Chavhan was entered in the above program, only "Pavan" was stored in the name string. It's because there was a space after Pavan.
&name with scanf().This is because name is a char array, and we know that array names decay to pointers in C.
Thus, the name in scanf() already points to the address of the first element in the string, which is why we don't need to use &.
- Program 2 :-
- Output :-
- Explanation :-
Here, we have used fgets() function to read a string from the user.
fgets(name, sizeof(name), stdlin); // read string
The sizeof(name) results to 30. Hence, we can take a maximum of 30 characters as input which is the size of the name string.
To print the string, we have used puts(name);.


If you have any doubts, Please let me know