codeGK
Code it ALL
C Strings - CodeGK
♦ C Strings

♣ About C Strings

In C Strings are array of characters giving out a text.
Strings are used in areas such as names, paragraphs, email, etc.

♣ Example1: String Declaration in C ?

A string can be declared by using character array.
Declaration of String allocates memory beforehand to initialization.
In this example, there is a declaration of character array of size 8.
Example
Input:
Output:

♣ Example2: String Initialization in C ?

Strings in C can be initialized in numerous ways.
In this example, we will see 4 ways to initialize same string "apple".
Example
Input:
Output:

♣ Example3: strlen() in C

strlen() is a in-built C method(function) to calculate length of initialized string.
In this example, the program will calculate the string length of array str.
Example
Input:
Output:

♣ Example4: strcpy() in C

strcpy() is a in-built C method(function) to copy a string to another string.
In this example, the program will copy string str1 into str2.
Example
Input:
Output:

♣ Example5: strcat() in C

strcat() is a in-built C method(function) for concatenating two strings.
In this example, the program will append string last to name.
Example
Input:
Output:

♣ Example6: strcmp() in C

strcmp() is a in-built C method(function) to compare two strings and output a result.
In this example, the program will compare string str1 and str2.
Example
Input:
Output:
Prev_LessonNext_Lesson