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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: None.
5. Which statement instructs gawk to stop processing the current data file?
a) next
b) nextfile
c) exit
d) exitfile
View Answer
Explanation: None.
6. What is the output of this program?
#! /usr/bin/awk -f
BEGIN {
a=5
while (a<5) {
print "sanfoundry"
a++;
}
}
a) nothing will print
b) “sanfoundry” will print 5 times
c) program will generate syntax error
d) none of the mentioned
View Answer
Explanation: The condition of while statement is false so commands inside the loop will not execute.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
root@ubuntu:/home/sanfoundry#
7. What is the output of this program?
#! /usr/bin/awk -f
BEGIN {
a=0
do {
print "sanfoundry"
a++
} while (a<5)
}
a) “sanfoundry” will print 4 times
b) “sanfoundry” will print 5 times
c) nothing will print
d) syntax error
View Answer
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
sanfoundry
sanfoundry
sanfoundry
sanfoundry
sanfoundry
root@ubuntu:/home/sanfoundry#
8. What is the output of this program?
#! /usr/bin/awk -f
BEGIN {
a=6
do {
print "sanfoundry"
a++
} while (a<5)
}
a) nothing will print
b) “sanfoundry” will print 5 times
c) “sanfoundry” will print 4 times
d) “sanfoundry” will print only 1 time
View Answer
Explanation: Even the condition is false of do-while loop, the body is executed once.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
sanfoundry
root@ubuntu:/home/sanfoundry#
9. What is the output of this program?
#! /usr/bin/awk -f
BEGIN {
for(i=0;i<=5;i++) {
print i
i++
}
}
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
View Answer
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
0
2
4
root@ubuntu:/home/sanfoundry#
10. The command “awk ‘{if (“9″>”10”) print “sanfoundry” else print “linux”}'”
a) will print “sanfoundry”
b) will print “linux”
c) will generate syntax error
d) none of the mentioned
View Answer
Explanation: Semicolon is required just before the else statement to parse the statement.
Output:
root@ubuntu:/home/sanfoundry# awk ‘{if (“9″>”10”) print “sanfoundry” else print “linux”}’
awk: {if (“9″>”10”) print “sanfoundry” else print “linux”}
awk: ^ syntax error
root@ubuntu:/home/sanfoundry#
Sanfoundry Global Education & Learning Series – Linux Administration & Programming.
Here’s the list of Best Books in Linux Commands & Shell Programming.
Here’s the list of Best Books in Linux Kernel, Device-Drivers & System Programming.
To practice all questions on Linux Administration & Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on Linux.
- Check Information Technology Books
- Practice Programming MCQs
- Apply for Programming Internship
- Check Linux Books