Strings cannot be assigned directly using the assignment operator once they have
been declared. Instead, functions such as strcpy are used to copy the contents
of one string into another.

Substrings are portions of a string that can be accessed using indexing or
pointer techniques. Proper string manipulation requires understanding both array
indexing and pointer arithmetic.
EXAMPLE:


#include <stdio.h>
#include <string.h>

int main() {
    char s1[] = "CocaCola";
    char s2[20]; 

    
    strcpy(s2, s1);

    printf("Original: %s\n", s1);
    printf("Copy:     %s\n", s2);

    return 0;
}
EXAMPLE:

#include <stdio.h>
#include <string.h>

int main() {
    char s1[] = "CocaCola";
    char s2[5];
    strncpy(s2, s1, 4);
    
    printf("%s", s2);
    return 0;
}
Previous Next