Logical Expressions

MATLAB

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

1. If a logical expression is true, it will always return a logical 1 and if it’s false, it’ll always return a 0.
a) True
b) False

2. The functioning of all() and any() is same.
a) True
b) False

3. What does the function all() do?
a) Returns 1 if all elements within it are 0
b) Returns 0 if all elements within it are 0
c) Returns 0 if all elements within it are non-zero
d) Returns 1 if all elements within it are non-zero

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

all([1 0])

a) 1
b) 0
c) Error
d) Nan

5. Choose the correct hierarchy of operations.
a) |,&,+,-
b) +,-,&,|
c) :,+,-,&
d) |,:,&,.^

6. What is the output of the following code?

2++++++++9

a) 11
b) 74
c) 25
d) Error

7. What is the output of the following code?

sin(Inf) & sin(nan)

a) Error
b) 1
c) 0
d) Nan

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

all([Nan])

a) 1
b) 0
c) Error
d) Nan

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

~xor(3476,1234)

a) 1
b) 0
c) Error
d) NaN

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

~or(~xor(1,1),~or(0,1))

a) 1
b) 0
c) NaN
d) Error

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

any(sin(0), NaN)

a) 1
b) Error
c) 0
d) No such function

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

any(xor(1,1), ~or(xor(1,0),1), sin(pi), NaN)

a) 0
b) 1
c) Error due to too many arguments
d) Error due to NaN

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

all([or(1,1), ~xor(xor(1,0),1), cos(pi)])

a) 0
b) 1
c) Error
d) No such function all

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

all(sin(pi), 1)

a) 0
b) 1
c) Error
d) NaN

15. The correct hierarchy of operations is ________
a) <.<=,|,&
b) >,>=,&,|
c) <,>=,|,&
d) <,|,>,&

16. ‘=’ is a?
a) Relational operator
b) Arithmetic operator
c) Operational operator
d) Assignment operator

17. What is the output of the following code?

sin(pi)~=0

a) NaN
b) 0
c) 1
d) Error

18. What is the output of the following code?

sin(Inf)~=NaN

a) 1
b) 0
c) Error
d) NaN

19. What is the output of the following code?

log(0)==Inf

a) 1
b) 0
c) Error
d) Inf

20. What is the output of the following code?

and(sin(pi),112312)

a) 1
b) 0
c) 00
d) Error

21. The ~ is ______
a) Quaternary operator
b) Relational Operator
c) Arithmetic Operator
d) Unary Operator

22. All logical operators operate on at least two operands.
a) True
b) False

23. What is the output of the following code?

NaN==Inf

a) 0
b) 1
c) Nan
d) Inf

24. What is the output of the following code?

Sin(Inf)==NaN

a) 0
b) 1
c) Nan
d) Inf

25. The precedence of : operator is after | and before &.
a) True
b) False

26. What is the output of the following code?

~xor(and(1,0),~xor(and(1,0),0))

a) 0
b) 1
c) NaN
d) Error

27. The precedence of Transpose operation is ____________
a) after &
b) after |
c) before .^
d) after ^

28. All relational operators operate on _______________
a) only real part of complex numbers
b) only imaginary part of complex numbers
c) complex numbers
d) numbers which are not complex

29. What is the output of the following code?

any([])

a) 0
b) 1
c) NaN
d) Error

30. What is the output of the following code?

all[1, 2, 3, NaN]

a) Error due to NaN
b) 1
c) 0
d) Syntactical Error

Leave a Reply

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