Strings

Introduction of Strings

String:- Strings are defined as an array of characters. The difference between a character array and a string is the string is terminated with a special character ‘\\0’.

Explain using figure:-

String

String and Character difference:-

1. character is a single element of character. the string is an array of characters.

2. string ends with a null character but in character, it is not possible

3. char ch; declaration of character in c language

4. char ch[10]; declaration of a string with size 10 in c language

Example of String:-

//print hello world string 
#include<stdio.h>
void main(){
   char s[]={'h','e','l','l','o',' ','w','o','r','l','d','\0'};
   printf("The String is %s",s);
}

 

String Methods and Functions

Different Programming languages support different String methods and function.  In this section Explain the String method in C Language

C language Support String methods and function:-

1. strcpy:- It is useful for strings copy

2.strcat:- It is useful for strings concatenation

3.strlrn:- It is useful for string length

4.strcmp:- It is useful for strings comparison

5.strchr:- It is useful for the first occurrence of character ch in string

6.strstr:- It is useful for first occurrence of string 2 in string 1