Back to Browse

#OPERATIONS ON #STRINGS| #LIBRARY #FUNCTIONS ON STRINGS| #EXAMPLES ON STRINGS|

214 views
Premiered Dec 26, 2022
32:34

The string is an important topic belonging to the world of programming and coding languages. And, when it comes to a competitive examination like GATE, you have to read the whole topic quite thoroughly. In this article, we have covered all the topics relevant to the string in C. We hope the notes for the CSE topics will help you understand this topic in a better way. What is a String in C? Syntax to Define the String in C How to Declare a String? Example of String in C Programming Function and Purpose of String Practice Problems – String in C What is String in C? A string in C is like an array of characters, pursued by a NULL character. For example: char c[] = “c string” String in C Syntax to Define the String in C char string_variable_name [array_size]; char c[] = “c string” How to Declare a String? There are two ways to declare a string in C language. By char array By string literal 1. By Char Array char greeting[6] = {‘T’, ‘a’, ‘b’, ‘l’, ‘e’, ‘\0’}; 2. By String Literal If you follow the rule of array initialisation, you can write the above statement as follows: char greeting[] = “Table”; Following is the memory presentation of the above-defined string in C/C++ − Memory presentation in String Function and Purpose of String: strcpy(s1, s2); – It is used to copy string s2 into string s1. strcat(s1, s2); – It is used to concatenate string s2 onto the end of string s1. strlen(s1); – It is used to return the length of string. strcmp(s1, s2); – It is used to analyse and compare the strings s1 and s2. Returns 0 if s1 and s2 are the same; less than 0 if s1LESS THANs2; greater than 0 if s1 GREATER THAN s2. strchr(s1, ch); – It is used to discover the foremost event or occurrence of a specified character within the actual string. strstr(s1, s2); – It is used to return a pointer to a character at the first index

Download

0 formats

No download links available.

#OPERATIONS ON #STRINGS| #LIBRARY #FUNCTIONS ON STRINGS| #EXAMPLES ON STRINGS| | NatokHD