A string is a sequence of characters stored together. Think of a string as a chain of letters, digits, or symbols that form words or sentences.
In C, strings are stored as arrays of characters (char type), but with a special ending called the null character '\0' which marks where the string finishes.
char name[10]; // Declares a string with space for 9 characters + null terminator
char greeting[] = "Hello"; // Automatically adds '\0' at the end
scanf or fgets to get user input.scanf("%s", name); // Reads a word (stops at space)
printf("%c\n", greeting[1]); // Prints 'e'
printf("%s\n", greeting); // Prints Hello
'\0': Every string ends with a special character '\0'. It tells the computer where the string ends.'\0'.'\0' at the end, functions like printf won’t know where to stop and may print garbage.'\0' when declaring or copying strings.
scanf("%s", ...) Without Size Limit:scanf("%9s", name); if the array size is 10 to leave space for '\0'.
char *str = "Hello"; are stored in read-only memory.strlen(), strcpy(), strcmp() in string.h to work with strings safely.char name[] = "Rohan";
printf("Name: %s\n", name);
name[0] = 'S'; // Changes "Rohan" to "Sohan"
printf("Updated Name: %s\n", name);
char input[20];
printf("Enter your name: ");
scanf("%19s", input); // Reads a word with max 19 chars + '\0'
printf("Hello, %s!\n", input);
#include <string.h>
char str1[20] = "Hello";
char str2[20];
strcpy(str2, str1); // Copies str1 into str2
printf("Copied string: %s\n", str2);
printf("Length: %lu\n", strlen(str2));
'\0'.string.h for common tasks.For more detailed explanations and examples, visit: