250+ TOP MCQs on Expressions and Answers

Linux / Unix questions and answers focuses on Expressions in Awk Programming.

1. What is expression in awk programming?
a) expression evaluates a value to print, test or pass to a function
b) expression assigns a new value to a variable or field
c) expression evaluates a value to print, test or pass to a function & also assigns a new value to a variable or field
d) none of the mentioned
Answer: c
Clarification: None.

2. Which one of the following is not true?
a) there are 3 types of constant expressions: numeric, string and regular
b) arithmetic operators are used to evaluate expressions
c) assignment expression is an expression that stores a value into a variable
d) comparison expressions does not compare strings for relationship
Answer: d
Clarification: None.

3. All numeric values are represented within awk in
a) double precision floating point
b) integer
c) exponential notation
d) fixed point
Answer: a
Clarification: None.

4. Concatenation is performed by
a) writing expressions next to one another, with no operator
b) conditional operator
c) relational operator
d) matching operator
Answer: a
Clarification: None.

5. The comparison expression “x ~ y” will true if
a) x is not equal to y
b) the string x does not match the regular expression denoted by y
c) the string x matches the regular expression denoted by y
d) none of the mentioned
Answer: c
Clarification: None.

6. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        print "20"<"9" ? "true":"false"	      
  4.    }

a) true
b) false
c) syntax error
d) none of the mentioned
Answer: a
Clarification: The operands of relational operators are converted to, and compared as string if both are not numbers. Strings are compared by comparing the characters of each. Hence 20 is less then 9.
Output:
[email protected]:/home/# chmod +x test.awk
[email protected]:/home/# ./test.awk
true
[email protected]:/home/#

7. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        a=10;
  4.        b=10;
  5.        print a==b ? "true":"false"	      
  6.    }

a) true
b) false
c) syntax error
d) none of the mentioned
Answer: a
Clarification: None.
Output:
[email protected]:/home/# chmod +x test.awk
[email protected]:/home/# ./test.awk
true
[email protected]:/home/#

8. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        var1=""
  4.        var2="linux"
  5.        print var1" provides "var2" MCQs "	      
  6.    }

a) provides linux MCQs
b) var1 provides var2 MCQs
c) provides MCQs
d) syntax error
Answer: a
Clarification: None.
Output:
[email protected]:/home/# chmod +x test.awk
[email protected]:/home/# ./test.awk
provides linux MCQs
[email protected]:/home/#

9. What is the output of this program?

  1.    #! /usr/bin/awk -f
  2.    BEGIN {
  3.        two=2;
  4.        two++;
  5.        print two 
  6.    }

a) two
b) three
c) 2
d) 3
Answer: d
Clarification: None.
Output:
[email protected]:/home/# chmod +x test.awk
[email protected]:/home/# ./test.awk
3
[email protected]:/home/#

10. What is the output of this program?

  1.     #! /usr/bin/awk -f
  2.     BEGIN {
  3.         one=10;
  4.         two=3;
  5.         print (one%two)+10 
  6.     }

a) (one%two)+10
b) 13
c) 11
d) syntax error
Answer: c
Clarification: The remainder of 10/3 is 1. remainder is added to 10.
Output:
[email protected]:/home/# chmod +x test.awk
[email protected]:/home/# ./test.awk
11
[email protected]:/home/#

Leave a Reply

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