Recent

Analytics.

Facebook

Paling Dilihat

String in C

A string is an array of characters. The end of the string is marked with a special character, thenull character, which is simply represented by '\0'. Strings are enclosed by double quotes whereas, character is enclosed by single quotes always.

Declaration :

Strings are array of char data type. It is declared as follow :

char s[5] ;

Initialization :

char message [20] = "Hello world !";

char message [20] = {'H', 'e', 'l', 'l', 'o', '\0'};

char message [] = "Hello!"

when we declare "char message[20]”, 20 bytes of memory space is allocated for the string value. And when we declare "char message[]”, memory space will be allocated as per the requirement during execution time of program.

String Handling Functions :

Sometimes, we need to manipulate string in our program according to our needs. For this C programming language provide us some in-built String Manipulation Functions which are available in <string.h> header file.

These functions are listed below :

strlen() :

strlen() function is used to count the number of characters in a string.

strcmp() function is used to compare two strings. If both strings are equal then function will return value zero(0). If first string is greater than second than function return value >0 otherwise <0. This function is case sensitive.