0% found this document useful (0 votes)
7 views15 pages

Understanding Strings in C Language

Strings in C are arrays of characters terminated by a null character ('\0'), and C does not have a built-in string data type. Strings can be declared using a character array or string literal, with the compiler automatically adding the null character. Various string manipulation functions are available in the 'string.h' library, including strlen(), strcpy(), strcat(), strcmp(), strrev(), strlwr(), and strupr().

Uploaded by

Akshat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views15 pages

Understanding Strings in C Language

Strings in C are arrays of characters terminated by a null character ('\0'), and C does not have a built-in string data type. Strings can be declared using a character array or string literal, with the compiler automatically adding the null character. Various string manipulation functions are available in the 'string.h' library, including strlen(), strcpy(), strcat(), strcmp(), strrev(), strlwr(), and strupr().

Uploaded by

Akshat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Strings in c

Introduction
String in C language is an array
of characters that is terminated
by \0 (null character).
C language does not support
strings as a data type.
There are two ways to declare
string in c language:
 By char array
 By string literal
Example of declaring string by
char array:

To hold the null character at the


end of the array, the size of the
character array containing the
string is one more than the number
of characters in the word "Hello."
 Following is the memory
presentation of the above defined
string in C−
While declaring string, size is not
mandatory.
Actually, you do not place
the null character at the end of a string
constant. The C compiler automatically
places the '\0' at the end of the string
when it initializes the array.
You can also define string by string
literal in C language. For example:

Insuch case, '\0' will be appended at


the end of string by the compiler.
Example
gets() and puts() functions
The gets() function reads string
from user and puts() function
prints the string.
Both functions are defined in
<stdio.h> header file.
Example
String Manipulation Functions
There are many important string
functions defined in "string.h"
library.
String Length: strlen() function
The strlen() function returns the
length of the given string.
It doesn't count null character '\
0'.
Copy String: strcpy()
The strcpy(destination, source)
function copies the source string
in destination.
String Concatenation: strcat()
The strcat(first_string,
second_string) function
concatenates two strings and
result is returned to first_string.
Compare String: strcmp()
The
strcmp(first_strin
g, second_string)
function
compares two
string and returns
0 if both strings
are equal.
Reverse String: strrev()
The strrev(string) function
returns reverse of the given
string.
String Lowercase: strlwr()
The strlwr(string) function returns
string characters in lowercase.
String Uppercase: strupr()
The strupr(string) function
returns string characters in
uppercase.

You might also like