click below
click below
Normal Size Small Size show me how
CP2-Module 1
User Defined Functions and Parameters
Question | Answer |
---|---|
There are two types of functions: | Built-in functions & User-defined functions |
A __________ is a block of code which only runs when it is called | function |
In C++, arguments to functions always appear within ______________. parenthesis curly braces double quotes double brackets | parentheses |
In order to define the absolute value of a number we should use: Absolute abz abs absol | abs |
The int max (int num1, int num2); code is a function _________________ : Error Call Declaration Parameter | Declaration |
Procedure, subprograms, and method are synonymous to functions. True or False? | True |
Which of the following is NOT a proper function prototype (definition)? char letter(); func(int x) void funct(); int secondfunct (char x, char y) ; | func(int x) |
The return type of the function double averageCall (double, double, double) is : double int char float | double |
The return type of the function float divide (float a, float b)) is : double int char float | float |
What will you use if you do NOT intended to return value? static const int void | void |
What symbol is used to end a function declaration? semicolon colon ampersand pound sign | semicolon |
In C++, which of the following is important in a function? Function name and return type Return Type Function name Parameter list | Function name and return type |
Which of the following function is used to accept user inputs? round cout return cin | cin |
It refers to the information that can be passed to a function Syntax Variable Parameter Statement | Parameter |
Which of the following function declaration using the default argument is correct? int foo(int x=5, int y, int z=10) all are correct int foo(int x, int y =5, int z=10) int foo(int x=5, int y =10, int z) | int foo(int x, int y =5, int z=10) |
Which value will it take when both user and default values are given? Default value None of the mentioned Custom value User value | Custom value |
When will we use the function overloading? Same function name but same number of arguments Same function name but different number of arguments Different function name but different number of arguments Different function name but same number o | Same function name but different number of arguments |
Which of the following returns an integer? int myRoundedGrade(int x) void myFinalGrade(int x, int y) double myAverageGrade(double x) void myInitialGrade(int x) | int myRoundedGrade(int x) |
Where does the “return statement” return the execution of the program? Group of answer choices main function caller function same function none of the given | caller function |
A function can return a value by calling using the keyword _____________ Group of answer choices void goto break return | return |
Which of the following does return a character? Group of answer choices void myGrade(int x, int y) int myGrade (double p, double q, double r) char myGrade(int x) double myGrade (double p, double q) | char |
If we start our function call with default arguments, then what will be the proceeding arguments? constant arguments user arguments empty arguments default arguments | empty arguments |
Where should default parameters appear in a function prototype? Middle of the parameter list Anywhere inside the parameter list To the rightmost side of the parameter list To the leftmost side of the parameter list | To the rightmost side of the parameter list |
What are the mandatory parts of a function declaration? parameter function name and return type variables return type, function name, parameters | function name and return type |
In C++, the block of code begins and ends with: {} [] () <> | {} |
The main function in C++ is __________________. int main() void main (String[] args) main (String [] args) Main (String [] args) | int main() |
It is the actual name of the function Return Type Parameters Function name Function body | Function name |
Which of the following function gets the ceiling of a number? Group of answer choices Ceils ceiling Ceil ceil | ceil |
A type of variable inside a function Constant Global Local Foreign | Local |
Which of the following is a valid function call (assuming the function exists)? functCall; int functCall(); functCall x, y; functCall(); | functCall(); |
What will happen when we use a void in argument passing? Error It will ask for an input It will not return a value to its caller It will return value to its caller | It will not return a value to its caller |
The function that returns no value is known as null static private function void function | void function |
What is the output of the following code? #include<iostream> using namespace std; int fun(int x = 0, int y = 0, int z=2) { return (x + y + z); } int main() { cout << fun(10); return 0; } Group of answer choices | 12 |
Where does the default parameter can be placed by the user? Leftmost middle none of the mentioned rightmost | rightmost |
What is the value that is returned in the following function? int getVolume() { int v; v = 23; if (v < 50) { return 50; } return v; } Group of answer choices 50 150 73 23 | 50 |
Where should default parameters appear in a function prototype? Anywhere inside the parameter list To the rightmost side of the parameter list Middle of the parameter list To the leftmost side of the parameter list | To the rightmost side of the parameter list |
A function that calls itself is a __________ function recursive overloaded void main | recursive |
What is the default argument of b in the function? int sum(int a, int b=10, int c=20); Group of answer choices 10 0 error 20 | 10 |
Two or more functions having the same name but different argument(s) are known as: main function overloaded function void function recursive function | overloaded function |
Which if the following is a way to pass an argument in C++? Call by Goto keyword Call by Reference Call by Value Call by Value and Call by Reference | Call by Value and Call by Reference |
If the user didn’t supply a value in a function, then what value will it take? none of the mentioned 0 rise an error default value | default value |
What is the output of the following code? #include<iostream> using namespace std; int fun(int x = 0, int y = 8, int z=2) { return (x + y + z); } int main() { cout << fun(10); return 0; } Group of answer choices | 20 |
A function may return a value (produce a value) or may perform some action without returning a value. True or False? | True |
Functions that do not return a value are called ______ functions. | void |
C++ comes with libraries of ________ functions that you can use in your programs. | predefined |
The following functions: abs, labs, fabs are valid functions in C++. True or False? | True |
C++ does not allow programmers to define their own functions. True or False? | False, C++ allows programmers to define their own functions. |
A __________ function groups code to perform a specific task and that group of code is given a name (identifier). | user-defined |
A function name is called a/an _______. | identifier |
When the function is _______ from any part of program, it executes the codes defined in the body of function. | invoked / called |
When a program runs, the system calls the _______ function, that is, the system starts executing codes from _______ function. | main() and main() |
How many minimum numbers of functions need to be present in a C++ program? | Only one, the main() function. |
Which of the following functions does NOT use the cmath library? | rand(), since it is in <cstdlib> |