Branching

MATLAB

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Branching”.

1. Amongst multiple elseif and nested if, which would take less runtime?
a) multiple elseif
b) nested if
c) elseif
d) elseif & nested if

2. What is the output of the following code?

if(x~=c)
p=0;
end

a) p=0
b) Output will be suppressed
c) Error
d) Cannot be determined

3. The end statement is given multiple times in _________
a) Multiple elseif
b) Nested if
c) elseif
d) if

4. What will happen if we don’t give an otherwise block to our switch structure?
a) Error
b) Infinitely demands a correct variable for case
c) Returns 0
d) Moves on to the next block

5. What is the output of the following code?

syms x;
if(x>50)
fprintf('Error')
end

a) Error
b) Prints Error
c) Does not print error
d) Cannot be determined

6. While developing a switch-case structure, the value for case can be _________
a) Single only
b) Multiple
c) Infinite
d) 0

7. What is the output of the following code?

syms x c; 
if(x~=c)
fprintf(‘Error’); 
end

a) Error
b) Error due to x
c) Error due to c
d) Error due to x and c

8. What is the output of the following code?

sym x c; 
if(x~=c)
fprintf('Error');
end

a) Error
b) Error due to x
c) Error due to c
d) Output suppressed

9. Menu-driven architecture should be done by ________
a) if-else structure
b) switch-case structure
c) stack
d) loop structure

10. The program to check the highest of n numbers can be done by ________
a) Sorting
b) If-else structure
c) Switch-case structure
d) Depends on the nature of n

11. Giving conditions using characters, we give them using ____
a) ‘’
b) ””
c) No special character
d) []

12. The if structure is a _________
a) Conditional structure
b) Logical structure
c) Nested structure
d) Biased structure

13. The switch-case structure is a _________
a) Conditional structure
b) Logical structure
c) Multidimensional structure
d) Hierarchical structure

14. What is the output of the following code?

if()
p=9;
end

a) Error
b) p=9
c) Output is suppressed but p=9
d) 0

15. What is the output of the following code?

if(x=99)
var=92;
end

a) Error
b) var=92
c) Output is suppressed but var=92
d) Nan

16. The if-else structure does not allow ___________
a) Return statement
b) End statement
c) Endif statement
d) Break statement

17. What is the output of the following code?

if((-10 &&00)||(20134 && 900))
fprintf("%s","True.")
else
fprintf("%s","False.")
end

a) True
b) False
c) Error
d) Nan

18. What is the output of the following code?

if(1)
p=9;
end

a) p=9
b) Output is suppressed but p=9
c) Error
d) Nan

19. What is the output of the following code?

num=2;
switch num
case[2 3 4]
p=9;
case[1 5 6]
q=9;
end

a) No output
b) p=9
c) q=9
d) Output suppressed but p=9

20. What will be the output of the following code?

switch num
case '2'
p=2;
case '2'
p=4-5;
end

a) p=2
b) Error
c) No output
d) p=-1

21. Before starting a new case, we have to end the previous case using ___________
a) Break statement
b) Continue statement
c) Return statement
d) No statement

22. We cannot use a ____ statement in the standalone if-else structure.
a) break
b) if-else
c) return
d) switch-case

23. The continue statement can be used in a switch-case structure.
a) True
b) False

24. We cannot use a ____ statement if the if-else structure is not part of a loop.
a) continue
b) if-else
c) clc
d) plot()

25. What will be the output of the following code?

if(cos(Inf)==NaN)
p=1;
end

a) p=1
b) Output suppressed but p=1
c) Error
d) No output

26. What will be the output of the following code?

switch num
case ‘a’
p=394;
case ‘b’
c=0;
end

a) Error
b) No output since we haven’t given num a value yet
c) p=394
d) c=0

Leave a Reply

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