Published on Oct 09,2014
583 Views
Email Post

String functions in C are represented as an array of characters ending with the null character ‘\0’. The null character indicates the end of the string. The space occupied by a String constant is one more than the number of characters. So, an extra byte of memory is required for storing ‘\0’.’\0′ is single character whose ASCII value is 0.Strings are always enclosed by double quotes. Whereas, character is enclosed by single quotes in C.

A String functions can be defined as :

Char str[]= “Hello World”;

The size of the above character array is 12 bytes, including the terminating null character  ‘\0’

Examples of String Functions:

Example 1:

#include<stdio.h>
Int main()
{
Char str[] = “Hello World”;
Printf (“%s\n”,str);
Printf(“Length: %d\nSize: %d\n”, strlen(str), sizeof(str));
System(“PAUSE”);
Return 0;
}

The output will be ‘Hello World’ , Length:11, Size:12 as shown below:

Example 2:

#include<stdio.h>
Int main()
{
Char str[] = “Hello World”;
Printf (“%c\n”,str[2]);
Printf(“Length: %d\nSize: %d\n”, strlen(str), sizeof(str));
System(“PAUSE”);
Return 0;
}

The output will be ‘l’, Length:11, Size:12 as shown below.

String Functions

Got a question for us? Mention them in the comments section and we will get back to you. 

Related Posts: 

C & Data Structures

Pointers in C

Explaining External Variables in C Programming

About Author
edureka
Published on Oct 09,2014

Share on

Browse Categories

Comments
0 Comments