0% found this document useful (0 votes)
6 views8 pages

Strings

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

Strings

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

Strings

Strings are a fundamental data type in C They enable us to represent and


.

manipulate text effectively


.
What are Strings?
A string is a sequence of characters. In C, they are typically enclosed in double quotes.

Immutability Variable Length

Strings are immutable. Once created, their contents cannot be Strings can have varying lengths. This allows us to represent
directly changed. text of different sizes.
String Types in C
Strings in C come in two main categories fixed length and variable length
: .

Fixed Length Variable Length


These strings have a These strings can adjust their
predetermined size They use
. size dynamically to
the same memory space accommodate varying text
regardless of the actual length lengths.

of the text
.
Variable Length Strings: Two
Types
Variable length strings can be further categorized into two types: length
controlled and delimited.

1 Length Controlled 2 Delimited


The length of the string is A special character known as
indicated by a count, which is a delimiter marks the end of
often stored as the first the string. The most common
character in the string. delimiter is a null character (
'\0' ).
Common String Functions
strlen() strcpy()
Calculates the length of a string Copies one string to another,
(number of characters). including the null character.

strcat() strcmp()
Concatenates (appends) one string Compares two strings
to the end of another. lexicographically. Returns 0 if they
are equal.
String Copy: strcpy() and strncpy()
The strcpy() function copies the contents of one string to another, including the null character. But it can overwrite memory if the
source string is longer.

Basic Copy Length Controlled


Syntax: strcpy(tostr, fromstr) Syntax: strncpy(tostr, fromstr, size)
String Concatenation: strcat() and strncat()
The strcat() function appends one string to the end of another string.

Basic Concatenation Length Controlled


Syntax: strcat(str1, str2) Syntax: strncat(str1, str2, size)
Mastering Strings
Understanding and mastering string manipulation is essential for effective C programming especially for applications requiring text
,

processing and performance .

1 Understanding String Basics

2 String Functions

3 String Manipulation Techniques

You might also like