Strings Class 12 Computer Notes and Questions

Notes Class 12 Revision Notes

Please refer to Strings Class 12 Computer notes and questions with solutions below. These revision notes and important examination questions have been prepared based on the latest Computer Science books for Class 12. You can go through the questions and solutions below which will help you to get better marks in your examinations.

Class 12 Computer Strings Notes and Questions

Fill ups and Multiple Choice Questions:

Question 1 What is the length of null string?

Answer

0 (zero)

Question 2 Every string must be terminated by __?

Answer

Null Character

Question 3 Which of the following function is used to reverse the string?

Answer

strrev

Question 4 Which of the following input function cannot be used to input multiword string?

Answer

scanf()

Question 5 The function strcmp (“Abcd” ,”ABCD”) will return?

Answer

Negative value

Question 6 Which of the following function is correct in case of conversion of string digits into their integer value?
a) x =atoi(string) b) x = stoi(string) c) x = chartoint(string) d) all of these

Answer

x =atoi(string)

Question 7 A string can be stored as an array of ______________

Answer

char

Question 8 The function strlen(“India is great”) will return the length of string ___________

Answer

14

Question 9 __________ function is used to read a complete string.

Answer

gets

Question 10_____________ function is used to read a character at a time.

Amswer

getchar

Question 11 How will you declare a string named student with length 50?

Answer

char student[50];

Question 12 If we consider the string declaration as “char x[10];”, what is the length of the string that can be correctly represented by x?

Answer

10

Question 13 Which of the following is correct, If we write strcmp(s1,s2), returns a value?
a) <0 when s1 0 when s1 > s2 d) all of these

Answer

all of these

Question 14 If the function strcat(s1,s2) is implemented , then the concatenation will return?

Answer

s2 at the end of s1

Question 15 Which of the following operation could not be performed on character string with string functions?
a) Combining a string b) copying a string to another c) Comparing strings for equality d) Removing a string

Answer

Removing a string

Question 16 C does not support the string data type however strings are handled as an array of?

Answer

char

Question 17 What is missing in this string initialization: char name[8] = {‘r’, ‘a’, ‘e’,‘t’ }?

Answer

\0

Question 18 To declare and initialized a empty string, a 10 element character array named x, we have char x[10] = “ “ ; What will be the other way for the same?

Answer

char x[10]={‘\0’};

State Whether True or False

Question 1 A string is represented as array of characters?

Answer

true

Question 2 strcpy() function is used to copy strings?

Answer

true

Question 3 To reverse a string, we need two string handling functions strcpy() & strcmp()?

Answer

false

Question 4 To use string library functions, we have to include header file string.h in our program?

Answer

true

Strings Class 12 Computer Exercise Questions

Question 1 What is special about the array of char?
Ans: char arrays have special importance in C Language. There is no data type in C to store strings. Therefore, to
store string data in, char arrays are being used in C language. To store strings in C, we have to declare char arrays.
For example:
char city[20];
In this example, char array named city has been declared which can store city name with maximum of 20 characters.

Question 2 What is string?
Ans: String is a combination of one or more characters. It is always enclosed in double quotes. They are terminated
by null character (\0) in c. To store strings in c, we use char array. For example:
char city[20];
It declares a string variable named city. It can store the string of maximum 20 characters.
Consider another example:
char city[20]=”Sunam\0”;
It initializes a string variable named city of length 20 and stores “Sunam” as string value. This value is terminated
with null character ‘\0’.

Question 3 What is the purpose of the null character?
Ans: Null character is also called empty character. It can be represented with the symbol ‘\0’. The length of null
character is C is zero. Null character is used to terminate the string in C language. For example:
char city[10]= “Sunam\0”;
It declares a string variable named city of length 10 and stores “Sunam” as string value. This value is terminated with
null character ‘\0’.

Question 4 Give the declaration for a string called student, which holds up to 50 characters. Show two ways to initialize the string in the declaration?
Ans: String declaration for student with 50 characters is:
char student[50];
Two methods for declaring strings are:
char student[50]=“Ram\0”;
char student[50]={‘R’, ‘a’, ‘m’,’\0’};

Question 5 What is the limit of char array?
Ans: Char arrays have a special importance in C language. There is not primitive data type to store string data in c.
therefore, to store string values in c, we have to use char arrays. Limit (length) of char array defines the length of
string. In c clanguage, maximum length of a string in char array can be 65535. Therefore, we can not extend the limit
of char array more than 65535.

Question 6 What is a difference between “A” and ‘A’?
Ans: “A” is a string while ‘A’ is a character. “A” is string because any string value must be enclosed in double quotes
and ‘A’ is char because any char value must be enclosed in single quotes in c language.
Question 7: Give the difference between putchar() and puts()?
Ans: The difference between putchar() and puts() functions is as follows:
puchar() function: This is the unformatted character output function. This function is used to output a single
unformatted character on the monitor screen.
puts() function: This is the unformatted string output function. This function is used to output an unformatted string
on the monitor screen.

Question 8 List the various functions that can be used to perform the I/O of the string data?
Ans: A string can be read-in or written-out using the input/output functions. Some of the commonly used string
input/output functions are explained below:
Reading Strings (String Input Functions):
scanf() : This function is used to input single word formatted string
gets() : This function is used to input multiword unformatted string
getchar() : This function is used to input unformatted single character
Writing Strings (String Output Functions):
printf() : This function is used to output formatted string
puts(): This function is used to output unformatted string
putchar(): This function is used to output unformatted single character

Question 9 Can we use scanf() to read a string? If no, then give reason. Why it is wrong to use the & symbol when reading in a string with scanf()?
Ans: Yes, we cam use scanf() to read a string. But this function can not be used to inpute multiword strings in C
language. There is not data type for storing string data in C. For this, we use char arrays. Name of an array in C
represents the address of the first element of array. So, when we use char array in scanf() function, array name itself
represents the address of string variable. So, it will be wrong to use the & symbol when reading a string with scanf()
function.

Question 10 What is stored in the str, if each of the following values, separately, is read in using a single call to scanf()? char str[10];
a) cityscape Ans: cityscape
b) New Delhi Ans: New
c) one or more blanks Ans: one

Question 1 Explain strlen() function with suitable example.
Ans: Function strlen() stands for string length. This function is used to count the total number of characters in the
given string. This function is present in the string.h header file. Therefore, to use this function, we have to include
the string.h header file in our program. Following code shows how to use this function:
strlen(“punjab”);
This function returns 6 as string length because the string “Punjab” contains 6 characters.

Question 2 Explain strrev() function with suitable example.
Ans: Function strrev stands for string reverse. This function is used to reverse the given string value. This function is
present in the string.h header file. Therefore, to use this function, we have to include the string.h header file in our
program. Following code shows how to use this function:
strrev(“Punjab”);
It reverses the given string to bajnuP.

Question 3 Explain strcpy() function with suitable example.
Ans: Function strcpy stands for string copy. This function is used to copy a string value into string variable. This
function is present in the string.h header file. Therefore, to use this function, we have to include the string.h header
file in our program. Following code shows how to use this function.
strcpy(str, “Punjab”);
It copy/store the string value “Punjab” into the string variable str.

Question 4 Explain strcat() function with suitable example.
Ans: Function strrev stands for string concatenation. This function is used to combines the two strings. It appends
2nd string value at the end of first string value. This function is present in the string.h header file. Therefore, to use
this function, we have to include the string.h header file in our program. Following code shows how to use this
function. Let the two strings are:
char str1[10]=“Sunam”;
char str2[10]=“City”;
strcat(str2, str1);
It adds value of str1 at the end of str2 and make it – CitySunam

Question 5 Explain strcmp() function with suitable example.
Ans: Function strcmp stands for string compares. The strcmp( ) function is used to compare two strings. It returns
one of the three possible values: zero, negative, or positive. It uses ASCII value of characters to compare strings. The
function strcmp() is present in the string.h header file. Therefore, to use this function, we have to include the string.h
header file in our program. Consider the the following example:
If ASCII values of 1st string is equal to ASCII values of 2nd string, It returns 0
e.g. strcmp(“punjab”,“punjab”) returns 0
If ASCII values of 1st string is less than the ASCII values of 2nd string, It returns negative value
e.g. strcmp(“india”,“punjab”) return –ve value
If ASCII values of 1st string is greater than ASCII values of 2nd string, It returns +ve value
e.g. strcmp(“punjab”,”india”) return +ve value

Question 6 Explain strupr() function with suitable example.
Ans: Function strupr stands for string upper. This function is used to convert the given string into Upper case (i.e. in
capital letter). This function is present in the string.h header file. Therefore, to use this function, we have to include
the string.h header file in our program. Following code shows how to use this function:
strupr(“Punjab”);
It converts the given string into PUNJAB.

Question 7 Explain strlwr() function with suitable example.
Ans: Function strlwr stands for string lower. This function is used to convert the given string into lower case (i.e. in
small letter). This function is present in the string.h header file. Therefore, to use this function, we have to include
the string.h header file in our program. Following code shows how to use this function:
strlwr(“PUNJAB”);
It converts the given string into punjab.

Question 8 Explain atoi () function with suitable example.
Ans: Function atoi stands for ascii to integer. This function converts the string number into integer value. This
function is present in the stdlib.h header file. Therefore, to use this function, we have to include the stdlib.h header
file in our program. Consider the following example:
atoi(“456”);
It will convert the string number “456” into integer value 456.

Strings Class 12 Computer

We hope the above Strings Class 12 Computer are useful for you. If you have any questions then post them in the comments section below. Our teachers will provide you an answer. Also refer to MCQ Questions for Class 12 Computer Science