1. Which one of the following statement is not true?
a) awk’s built-in functions can be categorised into three categories: numeric, string and I/O
b) built-in functions are always available to call
c) extra arguments to built-in function causes syntax error
d) we can also define the function in awk program
View Answer
Explanation: Extra arguments to built-in function causes fatal error.
2. What is the difference between the built-in functions rand() and srand() in awk programming?
a) rand() generates the random number but srand() does not generate the random number
b) rand() generates the same random number always whenever the program runs but srand() generates the different
c) srand() requires the seed() function but rand() does not require to produce the same result
d) none of the mentioned
View Answer
Explanation: None.
3. Which built-in function returns the arctangent of a/b in radians.
a) atan2(a/b)
b) atan(a/b)
c) atan_2(a/b)
d) none of the mentioned
View Answer
Explanation: None.
4. Which built-in function divides string into pieces seperated by fieldsep and stores the pieces in array?
a) split()
b) divide()
c) index()
d) sub()
View Answer
Explanation: None.
5. The built-in function tolower()
a) converts all lowercase characters into uppercase characters
b) returns the string with all lowercase characters
c) changes the nonalphabetic characters
d) none of the mentioned
View Answer
Explanation: None.
6. What is the output of this program?
#! /usr/bin/awk -f
BEGIN {
print log(1)
}
a) 0
b) syntax error
c) fatal error
d) segmentation fault
View Answer
Explanation: The function log() is built-in function and need not to be defined. This function calculates the natural logarithm of positive numbers.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
0
root@ubuntu:/home/sanfoundry#
7. What is the output of this program?
#! /usr/bin/awk -f
BEGIN {
print index("sanfoundry","linux")
}
a) sanfoundry linux
b) sanfoundry
c) 0
d) none of the mentioned
View Answer
Explanation: The function index() searches the string “sanfoundry” for the first occurence of the string “linux”. The function usually returns the character position but here the string is not found, hence function returns 0.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
0
root@ubuntu:/home/sanfoundry#
8. What is the output of this pogram?
#! /usr/bin/awk -f
BEGIN {
system("date")
print "sanfoundry"
}
a) the program will execute the date command and then program will print “sanfoundry”
b) program will generate fatal error because function system() is neither defined nor built-in function
c) program will generate syntax error because the syntax of function system() is wrong
d) none of the mentioned
View Answer
Explanation: The function system() allow to execute operating system command and then return to the awk program.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
Wed Apr 17 10:22:47 IST 2013
sanfoundry
root@ubuntu:/home/sanfoundry#
9. What is the output of the program?
#! /usr/bin/awk -f
BEGIN {
a=int(2.5)
print (a*20)
}
a) 50
b) 40
c) a*20
d) syntax error
View Answer
Explanation: The function int() returns the integer part of the value. In this program it returns 2.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
40
root@ubuntu:/home/sanfoundry#
10. What is the output of the program?
#! /usr/bin/awk -f
BEGIN {
print toupper("sAnFoUnDrY_1_$")
}
a) SANFOUNDRY_1_$
b) sAnFoUnDrY 1 $
c) SaNfOuNdRy_1_$
d) SANFOUNDRY
View Answer
Explanation: None.
Output:
root@ubuntu:/home/sanfoundry# ./test.awk
SANFOUNDRY_1_$
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
- Check Linux Books
- Apply for Programming Internship
- Practice Programming MCQs