Functions

Question 1
Study the following program: //precondition: x>=0 public void demo(int x) { System.out.print(x % 10); if (x % 10 != 0) { demo(x/10); } System.out.print(x%10); } Which of the following is printed as a result of the call demo(1234)?
A
1441
B
3443
C
12344321
D
43211234
       Programming       Functions       ISRO-2007
Question 1 Explanation: 
demo(1234) ---> First it will print “4” then 4!=10 condition is true again it call demo(123)
demo(123)------> It will print “3” then 3!=10 condition is true again it call demo(12)
demo(12)------> It will print “2” then 2!=10 condition is true again it call demo(1)
demo(1)------> It will print “1” then 1!=10 condition is true again it call demo(0)
It will print again 1,2,3 and 4 as there is another Print statement is in each function call.
Question 2
What is the output of this C++ program?  
A
910
B
920
C
870
D
900
       Programming-for-Output-Problems       Functions       ISRO-2017 May
Question 2 Explanation: 
Step-1: In main function, number variable has been initialized to 30.
Step-2: We pass address of number as parameters in the square function. As per the concept of function overloading in C++ the second square function will be executed.
Step-3: --(*y) will be executed first since decrement operator has the higher precedence than multiplication.
*x = (*x) * --(*y);
*x = 30 * 29;
*x = 870
Note: x is a pointer variable and it holds the address of the variable number.
Question 3
Consider the following C function
A
Call swap (a, b)
B
Call swap (&a, &b)
C
swap(a, b) cannot be used as it does not return any value
D
swap(a, b) cannot be used as the parameters passed by value
       Programming       Functions       ISRO-2017 May
Question 3 Explanation: 
Question 4
What is the output of the following program?
A
20 10 10
B
20 10 20
C
20 20 20
D
10 10 10
       Programming       Functions       ISRO-2017 May
Question 4 Explanation: 
Step-1: Every program starts execution from main() function.
Step-2: By default tmp value 20 will print initially.
Step-3: It calls fun() then it will print 10
Step-4: Again we are in main() function and printing value 20. Actually, the static value will return because its scope is a lifetime. But we are given tmp value as global. So, it prints 20 instead of 10.
Question 5
The cubic polynomial y(x) which takes the following values:
y(0) = 1,
y(1) = 0,
y(2) = 1,
y(3) = 10 is
A
x3 +2 x2 + 1
B
x3 + 3x2 + 1
C
x3 + 1
D
x3 – 2 x2 + 1
       Engineering-Mathematics       Functions       ISRO CS 2009
Question 5 Explanation: 
Substitute the values of x (0,1,2 and 3) in the options and check which option gives the corresponding y(x) values. The function x3 – 2 x2 + 1 gives the required values.
x = 0: y(x) = 1
x = 1: y(x) = 0
x = 2: y(x) = 8 - 8 + 1 = 1
x = 3: y(x) = 27 - 18 + 1 = 10
Question 6
Consider the polynomial, p(x) = a0 + a1X + a2X2 + a3X3 where ai ≠ 0, ∀i . The minimum number of multiplications needed to evaluate p on an input X is:
A
3
B
4
C
6
D
9
       Engineering-Mathematics       Functions       ISRO CS 2009
Question 6 Explanation: 
P(X)=a0+a1+a2X2+a3X3
=a0+X(a1+X(a2+a3X))
↓ ↓ ↓
③ ② ①
Here, minimum 3 multiplication needed
Question 7
The shift operator E is defined as E[f(xi)] = f(xi + h) and E'[f(xi)] = f(xi – h) then △ (forward difference) in terms of E is
A
E-1
B
E
C
1 – E-1
D
1 – E
       Engineering-Mathematics       Functions       ISRO CS 2009
Question 7 Explanation: 
Question 8
A root of equation f(x) = 0 can be computed to any degree of accuracy if a ‘good’ initial approximation x0 is chosen for which
A
f (x0) > 0
B
f (x0) f (x0)” > 0
C
f (x0) f (x0)” < 0
D
f (x0)” > 0
       Engineering-Mathematics       Functions       ISRO CS 2009
Question 9
What is the least value of the function f(x) = 2x2– 8x – 3 in the interval [ 0 , 5] ?
A
-15
B
7
C
-11
D
-3
       Engineering-Mathematics       Functions       ISRO CS 2013
Question 9 Explanation: 
One method is trial and error method
Substitute all the value of x from 0 to 5

The value of f(x) is -3 when x=0
The value of f(x) is -9 when x=1
The value of f(x) is -11 when x=2
The value of f(x) is -9 when x=3
The value of f(x) is -3 when x=4

The value of f(x) is -7 when x=5

so the least value is -11
Second method:
→We can solve this one by using derivatives.
→Given function is f(x) = 2x2 -8x -3
→ f'(x)=4x-8 (first derivative)
a f''(x)=4 (Second derivative)
Here we got constant value which means that it has minimal value at the point x=2
So we can find the minimum value by substituting value 2 in place of “x” in the given function.
Minimum value is 2⨉(2)2 -8⨉(2) -3= -11
Question 10
The keyboard used to transfer control from a function back to the calling function is:
A
Switch
B
Go to
C
go back
D
Retun
       Programming       Functions       Nielit Scientist-B IT 4-12-2016
Question 10 Explanation: 
● The return statement terminates the execution of a function and it returns the control to the calling function.
● The execution resumes in the calling function at a point immediately following the call.
Question 11
Output of following program?
#include
void dynamic(int s,..)
{
printf("%d",s);
}
int main()
{
dynamic(2,4,6,8);
dynamic(3,6,9);
return 0;
}
A
23
B
compile error
C
43
D
32
       Programming       Functions       Nielit Scientist-B IT 22-07-2017
Question 11 Explanation: 
● The latest compiler giving compilation error ​ “error: expected declaration specifiers or ‘...’ before ‘.’ toke​ n“
● Old compiler may support that syntax, in that syntax only first argument is defined which consists of remainings arguments but not defined.
● For the function call dynamic(2,4,6,8), first argument 2 is printed.
● For the function call dynamic(3,6,9);first argument 3 is printed.
Question 12
The following program
main()
{
  inc();
  inc();
  inc();
}
inc()
{
   static int x;
   printf("%d", ++x);
}
A
prints 012
B
prints 123
C
prints 3 consecutive, but unpredictable numbers
D
prints 111
       Programming-for-Output-Problems       Functions       ISRO CS 2015
Question 12 Explanation: 
In this question, we have to remind one point about “static” storage class.
Static storage class by default value is 0.
Step-1: We are calling inc( ) in main function. So, it will enter into inc() function.
Here, we are using pre increment function, so it replaced 0 with 1.
Step-2: Second inc() in main function. So, it will enter into inc() function.
Here, we are using pre increment function, so it replaced 1 with 2.
Step-3: Third inc() in main function. So, it will enter into inc() function.
Here, we are using pre increment function, so it replaced 2 with 3.
Note: The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope.
Question 13

In C language ______ is a process in which a function calls itself repeatedly until some specified condition has been satisfied

A
Infinite loop
B
Call by value
C
Call by reference
D
Recursion
       Programming       Functions       JT(IT) 2018 PART-B Computer Science
Question 13 Explanation: 
Recursion is a process in which a function calls itself repeatedly until some specified condition has been satisfied.
Question 14
A member function can always access the data in __________ , (in C++).
A
the class of which it is member
B
the object of which it is member
C
the public part of its class
D
the private part of its class
       Programming-in-c++       Functions       UGC NET CS 2017 Nov- paper-2
Question 14 Explanation: 
→ A member function can always access the data in the class of which it is member.
→ Functions within classes can access and modify (unless the function is constant) data members without declaring them, because the data members are already declared in the class.
Question 15
Which of the following is not correct (in C++) ?
A
Class templates and function templates are instantiated in the same way
B
Class templates differ from function templates in the way they are initiated
C
Class template is initiated by defining an object using the template argument
D
Class templates are generally used for storage classes
E
None of the above
       Programming-in-c++       Functions       UGC NET CS 2017 Nov- paper-2
Question 15 Explanation: 
(1) TRUE: Class templates and function templates are instantiated in the same way
(2) FALSE: Class templates differ from function templates in the way they are initiated
(3) FALSE: Class template is initiated by defining an object using the template argument
(4)FALSE: Class templates are generally used for storage classes
Question 16
Which of the following cannot be passed to a function in C++ ?
A
Constant
B
Structure
C
Array
D
Header file
       Programming-in-c++       Functions       UGC NET CS 2017 Jan -paper-2
Question 16 Explanation: 
→ Header files contain definitions of Functions and Variables, which is imported or used into any C++ program by using the pre-processor #include statement. Header file have an extension ".h" which contains C++ function declaration and macro definition.
→ Header file is a library file, we can not passed to a function in C++.
→ We can pass constant,Structure and Array
Question 17
If a function is friend of a class, which one of the following is wrong?
A
A function can only be declared a friend by a class itself.
B
Friend functions are not members of a class, they are associated with it.
C
Friend functions are members of a class.
D
It can have access to all members of the class, even private ones.
       OOPS       Functions       UGC NET CS 2016 Aug- paper-2
Question 17 Explanation: 
→ A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.
TRUE: function can only be declared a friend by a class itself.
TRUE: Friend functions are not members of a class, they are associated with it.
FALSE:Friend functions are members of a class.
TRUE: It can have access to all members of the class, even private ones.
Question 18
A function template in C++ provides _____ level of generalization.
A
4
B
3
C
2
D
1
       Programming-in-c++       Functions       UGC NET CS 2016 Aug- paper-2
Question 18 Explanation: 
→ ​ A function template in C++ provides 2 level of generalization.
→ Templates are a feature of the C++ programming language that allows functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one.
Question 19
When a method in a subclass has the same name and type signatures as a method in the super class, then the method in the subclass _____ the method in the super class.
A
Overloads
B
Friendships
C
Inherits
D
Overrides
       OOPS       Functions       UGC NET CS 2016 July- paper-2
Question 19 Explanation: 
→ When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass overrides the method in the superclass.
Question 20
A function object :
A
is an instance of a class for which operator ( ) is a member function.
B
is an instance of a class for which operator → is a member function.
C
is a pointer to any function
D
is a member function of a class
       Programming-in-c++       Functions       UGC NET CS 2004 Dec-Paper-2
Question 20 Explanation: 
A function object is an object to which the function call operator can be applied. Typically, it is a class that defines the function call operator (operator()()) as a member function. When a function object is used as a function, the function call operator is invoked whenever the function is called.
Question 21
Data members and member function of a class by default is respectively :
A
private and public
B
public
C
public and private
D
private
       Programming-in-c++       Functions       UGC NET CS 2005 Dec-Paper-2
Question 21 Explanation: 
If we do not specify any access modifiers for the members inside the class then by default the access modifier for the members will be Private.
Question 22
When a function is recursively called, all automatic variables :
A
are initialized during each execution of the function
B
are retained from the last execution
C
are maintained in a stack
D
are ignored
       Programming       Functions       UGC NET CS 2006 Dec-paper-2
Question 22 Explanation: 
→ When a function is recursively called, all automatic variables are initialized during each execution of the function. → Automatic local variables primarily applies to recursive lexically-scoped languages. An automatic variable is a local variable which is allocated and deallocated automatically when program flow enters and leaves the variable's scope. The scope is the lexical context, particularly the function or block in which a variable is defined.
Question 23
If we define the functions f, g and h that map R into R by : f(x) = x​ 4​ , g(x) = √ x 2 + 1 , h(x) = x​ 2​ + 72, then the value of the composite functions ho(gof) and (hog)of are given as
A
x​ 8​ – 71 and x​ 8​ – 71
B
x​ 8​ – 73 and x​8​ – 73
C
x​ 8​ + 71 and x​ 8​ + 71
D
x​ 8​ + 73 and x​ 8​ + 73
       Engineering-Mathematics       Functions       UGC NET CS 2014 Dec-Paper-2
Question 23 Explanation: 
Given f(x) = x​ 4​ , g(x) = √ x 2 + 1 , h(x) = x​ 2​ + 72
for, ho(gof)
gof=g(f(x))
=g(x​ 4​ )
=√(x​ 8​ +1)
ho(gof)=h(gof)
=h(√(x​ 8​ +1))
=(√(x​ 8​ +1)​ 2​ +72
=x​ 8​ +1+72
=x​ 8​ +73
√ x 2 + 1 , h(x) = x​ 2​ + 72
for, (hog)of,
hog=h(g(x))
=h(√(x​ 2​ +1)
=(√(x​ 2​ +1)​ 2​ +72
=x​ 2​ + 1+72
=x​ 2​ +73
(hog)of=(hog)(f(x))
=(hog)(x​ 4​ )
=(x​ 4​ )​ 2​ +73
=x​ 8​ +73
Hence, option-D is the correct answer
Question 24
Given below are three implementations of the swap( ) function in C++ :

Which of these would actually swap the contents of the two integer variables p and q ?
A
(a) only
B
(b) only
C
(c) only
D
(b) and (c) only
       Programming       Functions       UGC NET CS 2018 JUNE Paper-2
Question 24 Explanation: 
Module -(a) is call by value , so by using that code w can not swap the contents.
Module -(b) is call by reference , So the modification of content in the function reflects the changes in the main program. Swapping is done in the module -(b).
Module -(c) is passing addresses as parameters but in the functions definition , We are changing the addresses not the content So swapping of the values can’t be done.
Question 25
Match the following in List - I and List - II, for a function f :
A
(a)-(i), (b)-(ii), (c)-(iii)
B
(a)-(iii), (b)-(ii), (c)-(i)
C
(a)-(ii), (b)-(i), (c)-(iii)
D
(a)- (ii), (b)-(iii), (c)-(i)
       Engineering-Mathematics       Functions       UGC NET CS 2018 JUNE Paper-2
Question 25 Explanation: 
● The function is injective (one-to-one) if each element of the codomain is mapped to by at most one element of the domain. An injective function is an injection. Notationally:
∀ x, x ′ ∈ X , f (x) = f (x ′ ) ⇒ x = x ′
Or, equivalently (using logical transposition),
∀ x, x ′ ∈ X , x = / x ′ ⇒ f (x) = / f (x ′ )
● The function is surjective (onto) if each element of the codomain is mapped to by at least one element of the domain. (That is, the image and the codomain of the function are equal.) A surjective function is a surjection. Notationally:
∀ y ∈ Y , ∃x ∈ X such that y = f (x)
A constant function is a ​ function​ whose (output) value is the same for every input value. For example, the function y(x) =4 is a constant function because the value y(x) is 4 regardless of the input value x
Question 26
_______ is often used to prove the correctness of a recursive function.
A
Diagonalization
B
Communitivity
C
Mathematical Induction
D
Matrix Multiplication
       Programming       Functions       UGC NET CS 2013 Dec-paper-2
Question 26 Explanation: 
→ Mathematical Induction is often used to prove the correctness of a recursive function.
→ Mathematical Induction is a special way of proving things. It has only 2 steps:
Step-1: Show it is TRUE for the first one
Step-2: Show that if any one is TRUE then the next one is true
Then all are true
Question 27
Consider the function
find (int x, int y)
{return ((x < y) ? 0 : (x - y)) ; }
Let a, b be two non-negative integers. The call find {a, find(a, b)} can be used to find the
A
maximum of a, b
B
positive difference of a, b
C
sum of a, b
D
minimum of a, b
       Programming       Functions       NIELIT Technical Assistant_2016_march
Question 28
How many constructors can a class have ?
A
zero
B
2
C
2
D
any number
       Programming-in-c++       Functions       UGC NET CS 2008 Dec-Paper-2
Question 28 Explanation: 
There is no restriction to to have number of constructors in a lass.
There are 28 questions to complete.
PHP Code Snippets Powered By : XYZScripts.com