What is C-string? - C++

What is C-string? Explain with an example.

- C-string is null terminated string which is simply a null terminated character array. C-string is essentially C style string. It is different than the way C++ handles strings-by providing string class.
- Its general form of declaration is :
char var_name[size];
var_name is name given to the array variable.
- Please note while declaring a C-string, we need to declare it to be one character longer that the largest string that it is to hold. For example, to declare a C-string str that can hold 10 characters, we need to write :
char str[11];
- One extra location is reserved to store the null char at the end of the string.
- Some of the most commonly used C-string functions are :
strlen(s1)    returns length of s1
strcpy(s1, s2)   copies s2 into s1
strcmp(s1,s2)   returns 0 if s1 & s2 are same, less than 0 if
          s1 < s2, greater than 0 if s1 > s2.
Problem with C-string - C++
Problem with C-string - C-string can not contain 0 as a character in them. C-strings are essentially null terminated strings.....
Difference between struct and class in terms of Access Modifier
Difference between struct and class - All members of a class are private by default, whereas fields of a struct are public.....
What is private, public and protected inheritance?
What is private, public and protected inheritance? - The Public and protected members of Base class become private members of the derived class....
Post your comment