Computer Knowledge

Programming Languages and Compilers

2,284 Questions

Programming languages and compilers involve the rules, syntax, and semantics used to write and execute software programs. Key areas include scripting languages, object oriented concepts, and parsing algorithms like top down parsers. Practice these computer science questions to build proficiency for technical and computer knowledge exams.

Object oriented languagesScripting languagesCompilers and parsersProgramming syntax

Programming Languages and Compilers Questions

Multiple choice technology programming languages
  1. tidy

  2. trim

  3. chomp

  4. slim

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The chomp function is specifically designed in Perl to remove the trailing newline character from a string. It's commonly used after reading input from the keyboard or a file to clean up the input. The 'trim' and 'tidy' functions don't exist in Perl's core functionality.

Multiple choice technology programming languages
  1. The code will output the following: Masami 10 11 12 13

  2. The code will output the following: 10 Masami 10 11 12 13

  3. The code will output the following: 10 Masami 11 12 13 Niklas

  4. The code will output the following: Masami 10 11 12 13 Niklas

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The array @array is constructed as (10, 'Masami', 10, 11, 12, 13, 'Niklas') because 10..13 expands to (10,11,12,13). The for loop runs from i=1 to i < $#array (which is 6), so it iterates i=1,2,3,4,5. This prints elements at indices 1 through 5: 'Masami', 10, 11, 12, 13.

Multiple choice technology programming languages
  1. The code will output the following: 11 12 13 14 15 16 17 18 19

  2. The code will output the following: 10 11 12 13 14 16 18 20 22

  3. The code will output the following: 10 11 12 13 14 16 18 20

  4. The code will output the following: 10 11 12 13 14 15 16 17 18 19 20

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The loop starts with \$x = 10. For values 10 to 13, the else block increments \$x by 1. When \$x reaches 14, the if condition is met, \$x is incremented by 2 to 16, and redo restarts the loop without re-evaluating the condition, printing 16, then 18, then 20.

Multiple choice technology programming languages
  1. The code will output the following:123

  2. The code will output the following: 3

  3. The code will output the following:23

  4. The code will output the following: 321

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The first do-while loop prints y=1 once because $y eq 2 is false (1 != 2), so it exits after one iteration. The second do-until loop prints x=2 once because the condition $x eq 2 is immediately true, so it exits after one iteration. Finally, z=3 is printed. The output is: 1, 2, 3 (in that order).

Multiple choice technology web technology
  1. The <head> section

  2. Both the <head> section and the <body> section are correct

  3. The <body> section

  4. The <metadata> section

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

JavaScript can be placed in either the or section of an HTML page, making option B correct. Scripts in the section execute before the page renders (useful for early initialization), while scripts in the section can manipulate DOM elements as they load. The choice depends on when the JavaScript needs to run and whether it needs to access specific DOM elements. Option D is incorrect because there is no standard section in HTML.

Multiple choice technology web technology
  1. function:myFunction()

  2. function myFunction()

  3. function=myFunction()

  4. function=myFunction(){ }

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

JavaScript functions are declared using the 'function' keyword followed by the function name and parentheses, with the function body enclosed in curly braces. Option B shows the correct syntax. Options A, C, and D use incorrect separators (: or =) instead of a space, which are not valid JavaScript function declaration syntax.

Multiple choice technology web technology
  1. /This comment has more than one line/

  2. <//This comment has more than one line//

  3. <!--This comment has more than one line-->

  4. //This is a comment

Reveal answer Fill a bubble to check yourself
A,D Correct answer
Explanation

JavaScript supports two types of comments: single-line comments starting with // and multi-line comments enclosed between /* and */. Option A demonstrates multi-line comment syntax, while option D shows single-line comment syntax. Option B uses incorrect angle brackets with the comment markers, and option C shows HTML-style comments which are not valid JavaScript comments.

Multiple choice technology programming languages
  1. W

  2. X

  3. Y

  4. Z

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The code first sorts the array (W, X, Y), then uses unshift to add Z at the beginning. After unshift, @array becomes (Z, W, X, Y), so $array[0] is Z. Sorting arranges elements alphabetically, and unshift prepends elements to the array's start, modifying the index positions.

Multiple choice technology programming languages
  1. find

  2. index

  3. locate

  4. allocate

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Perl's index() function finds the first occurrence of a substring, returning the position or -1 if not found. This is the standard Perl function for substring search, making option B correct. Functions like find, locate, and allocate don't exist in Perl for this purpose - rindex() searches from the end, not first occurrence.

Multiple choice technology programming languages
  1. applesorangespearsplums

  2. apples oranges pears plums

  3. apples

  4. apples oranges pears plums

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The foreach loop iterates through @array1. Inside, $_ becomes each element. print "$\n" prints each element followed by newline. But since print is called without comma between $ and \n in double quotes, it prints each element with whitespace around it from the array's internal storage, resulting in spaces between words. Option D best represents this output.

Multiple choice technology programming languages
  1. The code will fail at line 1 because a hash cannot contain both numeric and string data.

  2. The code will execute without error but will output nothing.

  3. The code will output the following:32oz 16oz 8oz

  4. The code will output the following:large medium small

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Sorting the hash keys (large, medium, small) alphabetically yields the order: large, medium, small. Iterating through this sorted list and printing the corresponding hash values outputs 32oz, 16oz, and 8oz in sequence. The other options are incorrect because the code is syntactically valid (with barewords treated as strings) and produces this specific output.

Multiple choice technology programming languages
  1. The code will output the following:123

  2. The code will output the following: 3

  3. The code will output the following:23

  4. The code will output the following: 321

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The first do-while prints $y (value 1), then checks condition $y eq 2 (false since $y=1), so it exits. The second do-until prints $x (value 2), then checks $x eq 2 (true), so it exits after one iteration. Finally print $z outputs 3. The complete output is '123' printed sequentially.