250+ TOP MCQs on Arithmetic Expressions and Answers

Linux / Unix questions and answers focuses on Arithmetic Expression in Linux Bash Shell Programming.1. Which built-in command performs integer arithmetic in bash shell?
a) let
b) get
c) set
d) none of the mentionedAnswer: a
Clarification: None.

2. Which expression use the value of the enclosed arithmetic expression?
a) $(())
b) $()
c) ${}
d) $[].

Answer: a
Clarification: None.

3. If a and b are 2 variables then the meaning of a<<=b is
a) b = a << b
b) a = a << b
c) b = b << a
d) a = a << b

Answer: b
Clarification: None.

4. Which one of the following is bitwise ‘exclusive or’ operator?
a) ^=
b) |=
c) !=
d) none of the mentioned

Answer: a
Clarification: None.

5. Which one of the following is not a valid operator in bash shell?
a) ||
b) ~
c) =<<
d) -=

Answer: c
Clarification: None.

6. What is the output of this program?

  1.    #!/bin/bash
  2.    a=2
  3.    b=4
  4.    let c=a**b
  5.    echo $c
  6.    exit 0

a) 8
b) 16
c) 32
d) none of the mentioned

Answer: b

7. What is the output of this program?

  1.    #!/bin/bash
  2.    a=10; b=20
  3.    c=$((++a))
  4.    let a=c+a
  5.    echo $a
  6.    exit 0

a) 21
b) 22
c) program will generate an error message
d) none of the mentioned

Answer: b

8. What is the output of this program?

  1.    #!/bin/bash
  2.    a=10
  3.    b=$(( $a<0?10:$a<100 ))
  4.    echo $b
  5.    exit 0

a) 10
b) 20
c) 1
d) 0

Answer: c

9. What is the output of this program?

  1.    #!/bin/bash
  2.    a=10
  3.    b=$(( $a<0&&$a<100 ))
  4.    echo $b
  5.    exit 0

a) 10
b) 0
c) 1
d) none of the mentioned

Answer: b

10. What is the output of this program?

  1.     #!/bin/bash
  2.     a=1; b=2; c=3
  3.     d=$(( ++a**b*c++ + a ))
  4.     echo $d
  5.     exit 0

a) 14
b) 12
c) program will generate an error message
d) none of the mentioned

Answer: a

Leave a Reply

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