June 12, 2021

Commands for Parsing Input and Output – 1 MCQ’s

Read Time:4 Minute, 2 Second

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Commands for Parsing Input and Output – 1″.

1. What is the working of the varargout command?
a) Returns a 1*N cellular matrix
b) Returns a 1*N cell array of outputs
c) Returns a 1*N cell array of inputs given
d) Doesn’t exist

2. What is the working of the nargout command?
a) Gets assigned to a number which is equal to the number of outputs-1 sought from a subfunction
b) Gets assigned to a number which is equal to the number of outputs-1 sought from a function
c) Gets assigned to a number which is equal to the number of outputs sought from a function
d) Gets assigned to a number which is equal to the number of outputs+1 sought from a function

3. What is the working of the nargin keyword?
a) Returns the number of inputs to a function as an output of the same function
b) Gets assigned to a value equal to the number of inputs of a function
c) Gets assigned to a value equal to the number of inputs+1 of a function
d) Gets assigned to a value equal to the number of inputs-1 function

4. What is the output of the following command?

function s= average(varargin)
celldisp(varargin)
s=sum(varargin)
end
p=average(1:3)

a) Error in sum
b) Error using varargin in function definition
c) Error calling the average function
d)

    1 2 3
     p=6

5. What is the working of the varargin command?
a) takes 1*N inputs after the defined inputs in a function
b) takes N*1 inputs after the defined inputs in a function
c) takes N*N inputs after the defined inputs in a function
d) takes 1*1 inputs after the defined inputs in a function

6. What is the output of the following command?

function wish= ful(p,varargin)
celldisp(p)
wish=sin(varargin{1})
end
p=ful(1:3)

a) Error in calling the function
b) Error in celldisp
c) Error in the function definiton
d) Error in the wish variable

7. What is the output of the following command?

function mad= rush(p,varargin)
disp(p)
wish=cos(varargin[0])
end
p=rush(1:3,pi/2)

a) Error due to element index
b) Error due to syntax of varargin
c)

  1 2 3
  wish=0

d) Error due to disp()

8. What is the output of the following command?

function mad= heart(p,varargin)
disp(p)
wish=sin(varargin{0})
end
p=heart(1:3,0)

a) Error in wish command
b) Error while calling heart command
c) Error while calling disp command
d)

     1 2 3
     wish=0

9. What is the output of the following code?

function mad= rush(p,varargin)
disp(p)
wish=cos(varargin{1})
end
p=rush(1:3,Inf)

a) Error due to Inf
b) -1
c)

    p{1}= 1 2 3
    wish=0

d)

     p{1}= 1 2 3
     wish=NaN

10. What is the output of the following code?

function [die,absdif] = BDO(y,x)
die = y-x;
if nargout > 1
    disp('Boo !')
    absdif = abs(die);
end
end
[p,q]=BDO(Inf,Inf)

a)

     Boo!
     p=NaN
     q=NaN

b)

     Boo!
     p=0
     q=0

c) Error
d) p=NaN

11. What is the output of the following code?

function maha= orchid(polo,varargin)
disp(polo)
wish=sum(varargin{1,2})
end
p=rush(-1:1,Inf)

a) Logical error in varargin
b) Syntactical error in varargin
c)

     p{1}=-1 0 1
     wish=0

d) No output

12. What is the output of the following code?

function [die,af] = Bod(y,x)
die = y*x;
if nargout < 1
    error('Boo !')
 else
   disp(‘Yo !’)
   af = abs(die);
end
end
[p]=Bod(1,[1 -2])

a) Error with Boo! displayed
b)

     Yo !
     p=1

c)

     Yo !
     p=2

d)

     Yo !
     p=-2

13. A function ______________
a) can be run in the command window by defining it in the window itself
b) can be run in the command window by defining it in a cpp file
c) can be run in the command window by defining it in a script file
d) can be run in the script file by defining it in the command window

14. What is the output of the following code?

function [die,af] = lola(y,x)
die = y*x;
if nargout < 1
    error('Boo !')
 else
   disp(‘Yo !’)
   af = abs(die);
end
end
p=lola(1,[1 -2])

a) Error with Boo ! written
b)

     Yo !
     p=-2

c)

     Boo !
     p=-1

d)

     Boo !
     p=1

15. What is the output of the following code?

function c = addem(ap,q)
p=nargn-1
switch p
    case 2
        c = ap*q;
    case 1
        c = sin(q)
    otherwise
        c = 0;
end
addem(1,2,3,4,5,6,7,8)

a) 2
b) Error due to too many inputs
c) 28
d) Error due to nargn

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

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

Previous post More about Loops – 2 MCQ’s
Next post Commands for Parsing Input and Output – 2 MCQ’s