Assign String in C: Methods & Examples
In the C language, strings are typically represented using character arrays. Assigning a string can be done in several ways:
- Assign values using an array.
char str[10];
strcpy(str, "hello");
- Assign values using pointers.
char *str;
str = "hello";
- Assign values directly using a character array.
char str[] = "hello";
Please note that in C language, strings are terminated by a null character ‘\0’, so the size of the character array should be large enough to accommodate the string content as well as the terminating null character.