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
Answer: c
Clarification: 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
Answer: b
Clarification: 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
Answer: a
Clarification: 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()
Answer: a
Clarification: 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
Answer: b
Clarification: 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
Answer: a
Clarification: The function log() is built-in function and need not to be defined. This function calculates the natural logarithm of positive numbers.
Output:
[email protected]:/home/# ./test.awk
0
[email protected]:/home/#
7. What is the output of this program?
-
#! /usr/bin/awk -f
-
BEGIN {
-
print index("","linux")
-
}
a) linux
b)
c) 0
d) none of the mentioned
Answer: c
Clarification: The function index() searches the string “” 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:
[email protected]:/home/# ./test.awk
0
[email protected]:/home/#