250+ TOP MCQs on Control Statements and Answers

Linux / Unix questions and answers focuses on Control Statements in Awk Programming.1. The break statement
a) jumps out of the innermost for loop
b) jumps out of the innermost while loop
c) jumps out of the innermost do-while loop
d) all of the mentioned

Answer: d
Clarification: None.

2. Which statement skips over the rest of the loop body, causing the next cycle around the loop to begin immediately?
a) continue
b) break
c) next
d) none of the mentioned

Answer: a
Clarification: None.

3. The next statement
a) immediately stops processing the current record
b) go to the next record
c) immediately stops processing the current record & go to the next record
d) none of the mentioned

Answer: c
Clarification: None.

4. If the argument is supplied to the exit statement,
a) its value is used as the exit status code for the awk process
b) syntax error will generate
c) exit returns status 0
d) exit returns status 1

Answer: a
Clarification: None.

5. Which statement instructs gawk to stop processing the current data file?
a) next
b) nextfile
c) exit
d) exitfile

Answer: b
Clarification: None.

6. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a=5
  4.        while (a<5) {
  5.            print ""
  6.            a++;
  7.        }
  8.    }

a) nothing will print
b) “” will print 5 times
c) program will generate syntax error
d) none of the mentioned

Answer: a

7. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a=0
  4.        do {
  5.            print ""
  6.            a++
  7.        } while (a<5)
  8.    }

a) “” will print 4 times
b) “” will print 5 times
c) nothing will print
d) syntax error

Answer: b

8. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a=6
  4.        do {
  5.            print ""
  6.            a++
  7.        } while (a<5)
  8.    }

a) nothing will print
b) “” will print 5 times
c) “” will print 4 times
d) “” will print only 1 time

Answer: d

9. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        for(i=0;i<=5;i++) {
  4.            print i
  5.            i++
  6.        }
  7.    }

a) 0,2,4 will print
b) 1,3,5 will print
c) 1,2,3,4,5 will print
d) syntax error because i is not initialised

Answer: a

10. The command “awk ‘{if (“9″>”10”) print “” else print “linux”}’”
a) will print “”
b) will print “linux”
c) will generate syntax error
d) none of the mentioned

Answer: c

Leave a Reply

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