Coupon Accepted Successfully!



  • In C language Strings are defined as an array of characters or a pointer to a portion of memory containing ASCII characters. A string in C is a sequence of zero or more characters followed by a NULL ‘\0’ character:
  • It is important to preserve the NULL terminating character as it is how C defines and manages variable length strings.
  • String constants have double quote marks around them, and can be assigned to char pointers as shown below. Alternatively, you can assign a string constant to a char array - either with no size specified, or you can specify a size, but don’t forget to leave a space for the null character!

char *string_1 = “Hello”;

char string_2[] = “Hello”;

char string_3[6] = “Hello”;

String Manipulation Functions

  • char *strcpy (char *dest, char *src) - Copy src string string into dest string.
  • char *strncpy(char *string1, char *string2, int n) - Copy first n characters of string2 to stringl .
  • int strcmp(char *string1, char *string2) - Compare string1 and string2 to determine alphabetic order.
  • int strncmp(char *string1, char *string2, int n) - Compare first n characters of two strings.
  • int strlen(char *string) - Determine the length of a string.
  • char *strcat(char *dest, const char *src); - Concatenate string src to the string dest.
  • char *strncat(char *dest, const char *src, int n); - Concatenate n chracters from string src to the string dest.
  • char *strchr(char *string, int c) - Find first occurrence of character c in string.
  • char *strrchr(char *string, int c) - Find last occurrence of character c in string.
  • char *strstr(char *string2, char string*1) - Find first occurrence of string string1 in string2.
  • char *strtok(char *s, const char *delim) - Parse the string s into tokens using delim as delimiter.

C++ supports a wide range of functions that manipulate null-terminated strings:

Test Your Skills Now!
Take a Quiz now
Reviewer Name