10 Questions of the String in C Language free

1 Question : Explain String.

In C, String is stored internally as an array of characters. So a string is a group of characters of any length. A string enclosed within double quotation marks is known as a literal. For Example, “Hello” is a literal. The strings can be stored and manipulated as array of characters in C. The last character in a string is always “\0”, a null character with ASCII value equal to 0. Thus the effective size of an array of characters is one more than the size of string it can hold.

2 Question : How strings declared.

Strings are an array of characters. So they are generally declared like arrays but they have one property that is different from normal arrays. The last character in a string is end of string (EOS) marker, the “\0” character. So when you declare a string, you must allocate an extra character for this marker. An example of array declaration is:-

char item [9];

Where item is the name of the one dimensional character array having maximum 9 characters; 8 are the alphabets and one for the null character.

3 Question : How Strings are Reading and Writing.

A String can be read in or written out using the input / output statements.

Reading Strings: – The Following input functions can be used to read a string.

  1. scanf() with the %s format specification.
  2. gets() function
  3. getchar() function

Writing Strings: – A String or a group of strings can be written to the monitor using the following output functions.

  1. printf() with %s as format specification
  2. puts() function
  3. putchar() function

4 Question : Name a String Functions in C.

Some Commonly used string library functions are given below: –

  1. strlen() : – Finds the Length of the string.
  2. strcat() : – Appends one string at the end of another string.
  3. strcpy(): – Copies one string to another string.
  4. strcmp() : – Copmares two strings.
  5. strrev() : – Reverse the String.
  6. strupr() : – Converts string into uppercase.
  7. strlwr() :- Converts string into lowercase.

5 Question : What is the use of “strcat()” string function.

It appends a source string to the end of destination string so that the length of the resulting string is equal to total of both the strings. It takes two arguments, of which first is a string variable and second can be string constant or a variable.

String - E-Books

6 Question : Use of “strcpy()” string function.

This Function is used for copies one string to another. It requires two arguments, of which first is a string variable and second can be a string constant or a variable. It copies the characters of the second arguments to the first one. The general form of this function is given below: –

strcpy (dest, source);

It copies source string to dest string. The copying actions stops after the null character “\0″has moved from source to dest.

7 Question : Explain the Use of “strcmp()” string function.

The function is used for compare two strings. The comparison begins with the first character of both strings and continues with subsequent character until the end of the strings is reached or the compared characters differ from each other.

Suppose s1 and s2, here Strcmp() returns a value less than zero if s1<s2, zero if s1 = s2. It returns value more than zero if s1>s2. (In dictionary order).

8 Question : Use of “strrev()” string function.

This Function reverses the string i.e. the last character becomes the first one, the second last becomes the second one and so on. It take single argument i.e. string variable.

9 Question : Use of “strupr()” string function.

This function is used to convert the characters of a string into uppercase letters. It takes single argument i.e. string constant or a string variable.

10- Question : Use of “strlwr()”.

This Function is used to convert the characters of a string into lowercase letters. It also takes single arguments.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top