0% found this document useful (0 votes)
11 views3 pages

Functions (Q&A)

Uploaded by

kiranc2503
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Functions (Q&A)

Uploaded by

kiranc2503
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Chapter 12 Functions I PUC -CS

CHAPTER 12 FUNCTIONS
One mark questions
1. What is standard library function? (U)

ANS: A standard library is a collection of pre-defined functions which are accessed through

header files.
2. What is a function? (U)

ANS: A function is a named group of statements developed to solve a sub-problem and returns

a value to other functions when it is called.


3. Why is C++ standard library required? (K)

ANS: The C++ standard library provides a large number of library functions (under different

header files) for performing common tasks.


4. What are the different types of functions? (U)

ANS: 1. Library functions


2. User-defined functions
5.Give an example of header file? (U)

ANS: iostream.h
6.Write any one library function of iomanip.h (A)

ANS: endl, setw, setfile, setprecision, hex, oct etc

7.Define character array. (U)


ANS: A character array is a sequence of characters under single name.
8. Write the syntax to declare a string. (U)

ANS: char string_name[size];


9. Write any one library function of file string.h (A)

ANS: strlen(s), strcpy(s1, s2), strcat(s1, s2), strrev(s) …


10. Write the syntax of getline() function. (U)
ANS: cin.getline (string, size);
11. Write any one function of the header file ctype.h (K)
ANS: isalpha(c), isdigit(c), isalnum(c) , islower(c) …
12. Write one function of the header file math.h (K)
ANS: sqrt(x) , pow(x, y) , sin(x) , cos(x) …
13. Give the syntax of get() function. (U)
ANS: cin =get(ch); OR ch=cin.get(ch);

Page 1
Chapter 12 Functions I PUC -CS

14. Give the syntax of put() function. (U)


ANS: cout.put (ch);
15. Why do we use pow() function? (S)
ANS: To find the power of a number
16. Define user-defined function. (K)
ANS: A user-defined function is a complete and independent program, which can be used (or

invoked) by the main program, or by the other sub-programs.


17. Name any one function to generate pseudo-random number. (S)
ANS: random(n);
18. Name the header file to be included, to use the functions for generation of random numbers.
ANS: stdlib.h
Two mark questions:
1. How do we display a string using write() function? (A)
ANS: Syntax: cout.write (string, size);
Example: cout.write (st, 25);
2. What is string concatenation? What function is used to achieve this operation? (A)
ANS: The process of combining two strings to form a string is called as concatenation.

The general form is strcat(string1, string2);


Example:- char str1[ ]=”win”;
char str2[ ]=”dows8”;
strcat(str1,str2);
Output: str1 becomes “windows8”.
3. Distinguish between islower() and tolower() functions. (A)
ANS: islower(c) - It returns True if c is a lowercase letter otherwise False
tolower(c) - It converts c to lowercase letter
4. Distinguish between strcmp() and strcmpi() functions. (A)
ANS: This function is used to alphabetically compare a string with another string. This
function is case-sensitive. i.e., it treats the uppercase letters and lowercase letters as different.
The general form is : strcmp (string1, string2);
This function is used to alphabetically compare a string with another string. This function is
not case-sensitive. i.e., it treats the uppercase letter and lowercase letter as same.
The general form is: strcmpi (string1,string2);

Page 2
Chapter 12 Functions I PUC -CS

5. Write the difference between toupper() and isupper(). (A)


ANS: isupper(c) - It returns True if character is a uppercase letter otherwise False

toupper(c) - It converts character to uppercase letter


6. What are the different types of values strcmp() function return? (A)
ANS:
strcmp((s1,s2)==0)
strcmp((s1,s2)>0)
strcmp((s1,s2)<0)
It compares s1 and s2 and find out whether s1 equal s2, greater than s2 or s1 less than s2.

Page 3

You might also like