Strings
Strings are the sequence of characters terminated by a ‘\0’ NULL character. It is stored as the array of characters in C.
Syntax of Strings
char string_name [] = "any_text";
Example of Strings
C
// C program to illustrate strings #include <stdio.h> #include <string.h> int main() { // declare and initialize string char str[] = "Geeks" ; // print string printf ( "%s\n" , str); int length = 0; length = strlen (str); // displaying the length of string printf ( "Length of string str is %d" , length); return 0; } |
Geeks Length of string str is 5
C language provides some useful functions for string manipulation in <string.h> header file. Some of them are as follows:
S. No. |
Function |
Description |
---|---|---|
1. |
strlen() | Find the length of the string |
2. |
strcmp() | Compares two strings. |
3. |
strcpy() | Copy one string to another. |
4. |
strcat() | Concatenate one string with another. |
5. |
strchr() | Find the given character in the string. |
6. |
strstr() | Find the given substring in the string. |
C Cheat Sheet
This C Cheat Sheet provides an overview of both basic and advanced concepts of the C language. Whether you’re a beginner or an experienced programmer, this cheat sheet will help you revise and quickly go through the core principles of the C language.
In this Cheat Sheet, we will delve into the basics of the C language, exploring its fundamental concepts that lay the groundwork for programming. We will cover topics such as variables, data types, and operators, providing you with a solid understanding of the building blocks of C programming.